mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@52192 954022d7-b5bf-4e40-9824-e11837661b57
This commit is contained in:
3730
.gitattributes
vendored
Normal file
3730
.gitattributes
vendored
Normal file
File diff suppressed because it is too large
Load Diff
47
.gitignore
vendored
Normal file
47
.gitignore
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
AVSOfficeDocxFile2/AVSOfficeDocxFile2.ncb
|
||||
AVSOfficeDocxFile2/AVSOfficeDocxFile2.suo
|
||||
AVSOfficeDocxFile2/AVSOfficeDocxFile2.vcproj.AVSMEDIA.Dmitry.Davydov.user
|
||||
AVSOfficeDocxFile2/Debug
|
||||
AVSOfficeDocxFile2/DocWrapper/Debug
|
||||
AVSOfficeDocxFile2/DocWrapper/Release
|
||||
AVSOfficeDocxFile2/Release
|
||||
AVSOfficeDocxFile2/ReleaseAVSOfficeDocxFile2.pdb
|
||||
AVSOfficeDocxFile2/_AVSOfficeDocxFile2.h
|
||||
AVSOfficeDocxFile2/_AVSOfficeDocxFile2.idl
|
||||
AVSOfficeDocxFile2/_AVSOfficeDocxFile2.tlb
|
||||
AVSOfficeDocxFile2/_AVSOfficeDocxFile2_i.c
|
||||
AVSOfficeDocxFile2/_AVSOfficeDocxFile2_p.c
|
||||
AVSOfficeDocxFile2/avsgraphics.tlh
|
||||
AVSOfficeDocxFile2/avsimagestudio3.tlh
|
||||
AVSOfficeDocxFile2/avsmediacore3.tlh
|
||||
AVSOfficeDocxFile2/debug
|
||||
AVSOfficeDocxFile2/msxml3.tlh
|
||||
AVSOfficeDocxFile2/msxml3.tli
|
||||
AVSOfficeDocxFile2/release
|
||||
AVSOfficeOdpFile/*
|
||||
AVSOfficeOdpFile/ODPFormat/Debug
|
||||
AVSOfficeOdpFile/ODPFormat/ODPFormat.vcproj.AVSMEDIA.Viktor.Logunov.user
|
||||
AVSOfficeOdpFile/ODPFormat/ReadMe.txt
|
||||
AVSOfficeOdpFile/ODPFormat/Release
|
||||
AVSOfficeOdpFile/Odp2DrawingXML/Debug
|
||||
AVSOfficeOdpFile/Odp2DrawingXML/Release
|
||||
AVSOfficeOdtFile/Projects/*
|
||||
AVSOfficePPTXFile/*.suo
|
||||
AVSOfficePPTXFile/Debug
|
||||
AVSOfficePPTXFile/PPTX2DrawingXML/Debug
|
||||
AVSOfficePPTXFile/PPTX2DrawingXML/Release
|
||||
AVSOfficePPTXFile/PPTX2OfficeDrawing/Debug
|
||||
AVSOfficePPTXFile/PPTXFormat/!_
|
||||
AVSOfficePPTXFile/PPTXFormat/_
|
||||
AVSOfficePPTXFile/PPTXLib/PPTXFormat/*.suo
|
||||
AVSOfficePPTXFile/PPTXLib/PPTXFormat/PPTXFormat/Debug
|
||||
AVSOfficePPTXFile/PPTXLib/PPTXFormat/PPTXFormat/Release
|
||||
AVSOfficePPTXFile/PPTXLib/PPTXFormat/debug
|
||||
AVSOfficePPTXFile/PPTXLib/Source/!_
|
||||
AVSOfficePPTXFile/PPTXLib/Source/_
|
||||
AVSOfficePPTXFile/Release
|
||||
OfficeWebWord_release_2013-05-30/WebWord/menu/jquery/images/colorpicker_background.png
|
||||
OfficeWebWord_release_2013-05-30/WebWord/menu/jquery/images/colorpicker_hex.png
|
||||
OfficeWebWord_release_2013-05-30/WebWord/menu/jquery/images/colorpicker_hsb_b.png
|
||||
OfficeWebWord_release_2013-05-30/WebWord/menu/jquery/images/colorpicker_hsb_h.png
|
||||
OfficeWebWord_release_2013-05-30/WebWord/menu/jquery/images/colorpicker_hsb_s.png
|
||||
80
.gitsvnextmodules
Normal file
80
.gitsvnextmodules
Normal file
@ -0,0 +1,80 @@
|
||||
[submodule "OfficeWebCommon_release_2013-05-30/FontsFreeType"]
|
||||
path = OfficeWebCommon_release_2013-05-30/FontsFreeType
|
||||
owner = OfficeWebCommon_release_2013-05-30
|
||||
url = svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Common/FontsFreeType
|
||||
branch = /
|
||||
fetch = :refs/remotes/git-svn
|
||||
remote = svn
|
||||
type = dir
|
||||
[submodule "OfficeWebCommon_release_2013-05-30/FontsFreeType/FontFiles"]
|
||||
path = OfficeWebCommon_release_2013-05-30/FontsFreeType/FontFiles
|
||||
owner = OfficeWebCommon_release_2013-05-30
|
||||
url = svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Fonts/js
|
||||
branch = /
|
||||
fetch = :refs/remotes/git-svn
|
||||
remote = svn
|
||||
type = dir
|
||||
[submodule "OfficeWebCommon_release_2013-05-30/FontsFreeType/FontFiles/TrueType"]
|
||||
path = OfficeWebCommon_release_2013-05-30/FontsFreeType/FontFiles/TrueType
|
||||
owner = OfficeWebCommon_release_2013-05-30
|
||||
url = svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Fonts/native
|
||||
branch = /
|
||||
fetch = :refs/remotes/git-svn
|
||||
remote = svn
|
||||
type = dir
|
||||
[submodule "OfficeWebWord_release_2013-05-30/FontsFreeType/FontFiles"]
|
||||
path = OfficeWebWord_release_2013-05-30/FontsFreeType/FontFiles
|
||||
owner = OfficeWebWord_release_2013-05-30/FontsFreeType
|
||||
url = svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Fonts/js
|
||||
branch = /
|
||||
fetch = :refs/remotes/git-svn
|
||||
remote = svn
|
||||
type = dir
|
||||
[submodule "OfficeWebWord_release_2013-05-30/FontsFreeType/FontFiles/TrueType"]
|
||||
path = OfficeWebWord_release_2013-05-30/FontsFreeType/FontFiles/TrueType
|
||||
owner = OfficeWebWord_release_2013-05-30/FontsFreeType
|
||||
url = svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Fonts/native
|
||||
branch = /
|
||||
fetch = :refs/remotes/git-svn
|
||||
remote = svn
|
||||
type = dir
|
||||
[submodule "VKDocs/bin/ASC.Common.dll"]
|
||||
path = VKDocs/bin/ASC.Common.dll
|
||||
owner = VKDocs/bin
|
||||
url = svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/wwwroot/Bin/ASC.Common.dll
|
||||
branch = /
|
||||
fetch = :refs/remotes/git-svn
|
||||
remote = svn
|
||||
type = dir
|
||||
[submodule "VKDocs/bin/ASC.Core.Common.dll"]
|
||||
path = VKDocs/bin/ASC.Core.Common.dll
|
||||
owner = VKDocs/bin
|
||||
url = svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/wwwroot/Bin/ASC.Core.Common.dll
|
||||
branch = /
|
||||
fetch = :refs/remotes/git-svn
|
||||
remote = svn
|
||||
type = dir
|
||||
[submodule "VKDocs/bin/MySql.Data.dll"]
|
||||
path = VKDocs/bin/MySql.Data.dll
|
||||
owner = VKDocs/bin
|
||||
url = svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/wwwroot/Bin/MySql.Data.dll
|
||||
branch = /
|
||||
fetch = :refs/remotes/git-svn
|
||||
remote = svn
|
||||
type = dir
|
||||
[submodule "VKDocs/bin/System.Data.SQLite.dll"]
|
||||
path = VKDocs/bin/System.Data.SQLite.dll
|
||||
owner = VKDocs/bin
|
||||
url = svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/wwwroot/Bin/System.Data.SQLite.dll
|
||||
branch = /
|
||||
fetch = :refs/remotes/git-svn
|
||||
remote = svn
|
||||
type = dir
|
||||
[submodule "VKDocs/bin/log4net.dll"]
|
||||
path = VKDocs/bin/log4net.dll
|
||||
owner = VKDocs/bin
|
||||
url = svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/wwwroot/Bin/log4net.dll
|
||||
branch = /
|
||||
fetch = :refs/remotes/git-svn
|
||||
remote = svn
|
||||
type = dir
|
||||
14
AVSEBOOKWriter/AVSEBOOKWriter.cpp
Normal file
14
AVSEBOOKWriter/AVSEBOOKWriter.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// AVSEBOOKWriter.cpp : Implementation of DLL Exports.
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "resource.h"
|
||||
|
||||
#include "EBOOKWriter.h"
|
||||
#include "MobiFormat/MobiFile.h"
|
||||
|
||||
// The module attribute causes DllMain, DllRegisterServer and DllUnregisterServer to be automatically implemented for you
|
||||
[ module(dll, uuid = "{218DB989-85F3-4512-8A6D-71A7211FBC5A}",
|
||||
name = "AVSEBOOKWriter",
|
||||
helpstring = "AVSEBOOKWriter 1.0 Type Library",
|
||||
resource_name = "IDR_AVSEBOOKWRITER") ];
|
||||
146
AVSEBOOKWriter/AVSEBOOKWriter.rc
Normal file
146
AVSEBOOKWriter/AVSEBOOKWriter.rc
Normal file
@ -0,0 +1,146 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
#define COMPONENT_NAME "EBOOKWriter"
|
||||
#include "../../../../Common/FileInfo.h"
|
||||
#include "version.h"
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE 9, 1
|
||||
#pragma code_page(1251)
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Document
|
||||
//
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""winres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION INTVER
|
||||
PRODUCTVERSION INTVER
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904B0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", COMPANY_NAME
|
||||
VALUE "FileDescription", FILE_DESCRIPTION_ACTIVEX
|
||||
VALUE "FileVersion", STRVER
|
||||
VALUE "LegalCopyright", LEGAL_COPYRIGHT
|
||||
VALUE "InternalName", COMPONENT_FILE_NAME_DLL
|
||||
VALUE "OriginalFilename", COMPONENT_FILE_NAME_DLL
|
||||
VALUE "ProductName", FILE_DESCRIPTION_ACTIVEX
|
||||
VALUE "ProductVersion", STRVER
|
||||
VALUE "OLESelfRegister", ""
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0409, 0x04B0
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// REGISTRY
|
||||
//
|
||||
|
||||
IDR_AVSEBOOKWRITER REGISTRY "AVSEBOOKWriter.rgs"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_PROJNAME "AVSEBOOKWriter"
|
||||
END
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
11
AVSEBOOKWriter/AVSEBOOKWriter.rgs
Normal file
11
AVSEBOOKWriter/AVSEBOOKWriter.rgs
Normal file
@ -0,0 +1,11 @@
|
||||
HKCR
|
||||
{
|
||||
NoRemove AppID
|
||||
{
|
||||
'%APPID%' = s 'AVSEBOOKWriter'
|
||||
'AVSEBOOKWriter.DLL'
|
||||
{
|
||||
val AppID = s '%APPID%'
|
||||
}
|
||||
}
|
||||
}
|
||||
22
AVSEBOOKWriter/AVSEBOOKWriter.sln
Normal file
22
AVSEBOOKWriter/AVSEBOOKWriter.sln
Normal file
@ -0,0 +1,22 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual C++ Express 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AVSEBOOKWriter", "AVSEBOOKWriter.vcproj", "{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
ReleaseASC|Win32 = ReleaseASC|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}.Release|Win32.Build.0 = Release|Win32
|
||||
{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}.ReleaseASC|Win32.ActiveCfg = ReleaseASC|Win32
|
||||
{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}.ReleaseASC|Win32.Build.0 = ReleaseASC|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
1036
AVSEBOOKWriter/AVSEBOOKWriter.vcproj
Normal file
1036
AVSEBOOKWriter/AVSEBOOKWriter.vcproj
Normal file
File diff suppressed because it is too large
Load Diff
87
AVSEBOOKWriter/Common/CalculatorCRC32.h
Normal file
87
AVSEBOOKWriter/Common/CalculatorCRC32.h
Normal file
@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
const long g_clFilePartSize = 20*1024;
|
||||
class CCalculatorCRC32
|
||||
{
|
||||
public:
|
||||
CCalculatorCRC32()
|
||||
{
|
||||
m_dwMagicWord = 0xEDB88320;
|
||||
m_dwInitCrc = 0xFFFFFFFF;
|
||||
m_bInitTable = FALSE;
|
||||
}
|
||||
public:
|
||||
DWORD Calc(BYTE const*pStream, int nSize)
|
||||
{
|
||||
InitCRCTable();
|
||||
DWORD dwRes = m_dwInitCrc;
|
||||
for (int i=0;i<nSize;i++)
|
||||
{
|
||||
dwRes = m_arCRCTable[(dwRes ^ pStream[i])& 0xFF] ^ (dwRes >> 8);
|
||||
}
|
||||
|
||||
dwRes = dwRes ^ 0xFFFFFFFF;
|
||||
return dwRes;
|
||||
}
|
||||
|
||||
DWORD Calc(const CString &sStream)
|
||||
{
|
||||
InitCRCTable();
|
||||
DWORD dwRes = m_dwInitCrc;
|
||||
int nSize = sStream.GetLength();
|
||||
for (int i=0;i<nSize;i++)
|
||||
{
|
||||
dwRes = m_arCRCTable[(dwRes ^ (BYTE)sStream[i]) & 0xFF] ^ (dwRes >> 8);
|
||||
}
|
||||
|
||||
dwRes = dwRes ^ 0xFFFFFFFF;
|
||||
return dwRes;
|
||||
}
|
||||
DWORD CalcPartFile(const CString &sFilepath)
|
||||
{
|
||||
DWORD dwRet = 0xFFFFFFFF;
|
||||
//LPBYTE pBuffer = new BYTE[g_clFilePartSize];
|
||||
//if (NULL==pBuffer)
|
||||
// return dwRet;
|
||||
//FILE *pFile = fopen(sFilepath, "rb");
|
||||
//if (NULL==pFile)
|
||||
//{
|
||||
// delete [] pBuffer;
|
||||
// return dwRet;
|
||||
//}
|
||||
|
||||
//size_t nReaded = fread(pBuffer, 1, 1024, pFile);
|
||||
//fclose(pFile);
|
||||
|
||||
//dwRet = CCalculatorCRC32::Calc(pBuffer, nReaded);
|
||||
//
|
||||
////ATLTRACE("CRC32: 0x%08X\n", dwRet);
|
||||
//delete [] pBuffer;
|
||||
return dwRet;
|
||||
}
|
||||
private:
|
||||
void InitCRCTable()
|
||||
{
|
||||
if (m_bInitTable)
|
||||
return;
|
||||
|
||||
DWORD dwTemp;
|
||||
for (int i=0;i<256;i++)
|
||||
{
|
||||
dwTemp = i;
|
||||
for (int j=0;j<8;j++)
|
||||
{
|
||||
if (0x1==(dwTemp & 0x1))
|
||||
dwTemp = (dwTemp >> 1) ^ m_dwMagicWord;
|
||||
else
|
||||
dwTemp = dwTemp >> 1;
|
||||
}
|
||||
m_arCRCTable[i] = dwTemp;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD m_dwMagicWord;
|
||||
DWORD m_dwInitCrc;
|
||||
DWORD m_arCRCTable[255];
|
||||
BOOL m_bInitTable;
|
||||
};
|
||||
610
AVSEBOOKWriter/Common/Common.h
Normal file
610
AVSEBOOKWriter/Common/Common.h
Normal file
@ -0,0 +1,610 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef AVSINLINE
|
||||
#if defined(_MSC_VER)
|
||||
#define AVSINLINE __forceinline
|
||||
#else
|
||||
#define AVSINLINE inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "TemporaryCS.h"
|
||||
#include "Matrix.h"
|
||||
#include "Structures.h"
|
||||
#include "StringWriter.h"
|
||||
#include "CalculatorCRC32.h"
|
||||
|
||||
const double c_dpiBook = 166;
|
||||
const long c_nMaxImageSize = 800;
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
AVSINLINE LONG ConvertColor(LONG lBGR)
|
||||
{
|
||||
return (0x00FFFFFF & (((lBGR & 0xFF) << 16) | (lBGR & 0x0000FF00) | ((lBGR >> 16) & 0xFF)));
|
||||
}
|
||||
|
||||
AVSINLINE void CorrectString(CString& strValue)
|
||||
{
|
||||
strValue.Replace(_T("&"), _T("&"));
|
||||
strValue.Replace(_T("'"), _T("'"));
|
||||
strValue.Replace(_T("<"), _T("<"));
|
||||
strValue.Replace(_T(">"), _T(">"));
|
||||
strValue.Replace(_T("\""), _T("""));
|
||||
}
|
||||
AVSINLINE CString CorrectString2(CString& str)
|
||||
{
|
||||
CString strValue = str;
|
||||
CorrectString(strValue);
|
||||
return strValue;
|
||||
}
|
||||
|
||||
class CDoubleRect
|
||||
{
|
||||
public:
|
||||
double left;
|
||||
double top;
|
||||
double right;
|
||||
double bottom;
|
||||
|
||||
public:
|
||||
CDoubleRect()
|
||||
{
|
||||
left = 0;
|
||||
top = 0;
|
||||
right = 0;
|
||||
bottom = 0;
|
||||
}
|
||||
CDoubleRect& operator=(const CDoubleRect& oSrc)
|
||||
{
|
||||
left = oSrc.left;
|
||||
top = oSrc.top;
|
||||
right = oSrc.right;
|
||||
bottom = oSrc.bottom;
|
||||
|
||||
return *this;
|
||||
}
|
||||
CDoubleRect(const CDoubleRect& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
inline bool IsEqual(const CDoubleRect& oSrc, double dEps = 0.01)
|
||||
{
|
||||
return ((fabs(left - oSrc.left) < dEps) && (fabs(top - oSrc.top) < dEps) &&
|
||||
(fabs(right - oSrc.right) < dEps) && (fabs(bottom - oSrc.bottom) < dEps));
|
||||
}
|
||||
|
||||
inline double GetWidth() const
|
||||
{
|
||||
return right - left;
|
||||
}
|
||||
inline double GetHeight() const
|
||||
{
|
||||
return bottom - top;
|
||||
}
|
||||
inline void Scale(const double& dKoef)
|
||||
{
|
||||
left *= dKoef;
|
||||
top *= dKoef;
|
||||
right *= dKoef;
|
||||
bottom *= dKoef;
|
||||
}
|
||||
|
||||
AVSINLINE void ClearBounds()
|
||||
{
|
||||
left = 1000000;
|
||||
top = 1000000;
|
||||
right = -1000000;
|
||||
bottom = -1000000;
|
||||
}
|
||||
|
||||
AVSINLINE void CheckBounds(const double& x, const double& y)
|
||||
{
|
||||
if (left > x)
|
||||
left = x;
|
||||
if (right < x)
|
||||
right = x;
|
||||
if (top > y)
|
||||
top = y;
|
||||
if (bottom < y)
|
||||
bottom = y;
|
||||
}
|
||||
};
|
||||
|
||||
class CImageManager
|
||||
{
|
||||
public:
|
||||
CAtlMap<CString, CImageInfo> m_mapImagesFile;
|
||||
CAtlMap<DWORD, CImageInfo> m_mapImageData;
|
||||
|
||||
CAtlList<CImageInfo> m_listImages;
|
||||
|
||||
CString m_strDstMedia;
|
||||
|
||||
LONG m_lMaxSizeImage;
|
||||
LONG m_lNextIDImage;
|
||||
|
||||
CCalculatorCRC32 m_oCRC;
|
||||
|
||||
LONG m_lDstFormat;
|
||||
|
||||
public:
|
||||
|
||||
CImageManager()
|
||||
{
|
||||
m_strDstMedia = _T("");
|
||||
m_lMaxSizeImage = c_nMaxImageSize;
|
||||
m_lNextIDImage = 0;
|
||||
m_lDstFormat = 0;
|
||||
}
|
||||
|
||||
AVSINLINE void NewDocument()
|
||||
{
|
||||
m_strDstMedia = _T("");
|
||||
m_lMaxSizeImage = 800;
|
||||
m_lNextIDImage = 0;
|
||||
|
||||
m_mapImageData.RemoveAll();
|
||||
m_mapImagesFile.RemoveAll();
|
||||
m_listImages.RemoveAll();
|
||||
}
|
||||
|
||||
public:
|
||||
CImageInfo WriteImage(IUnknown* punkImage, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
CImageInfo info;
|
||||
if (NULL == punkImage)
|
||||
return info;
|
||||
|
||||
if (height < 0)
|
||||
{
|
||||
FlipY(punkImage);
|
||||
height = -height;
|
||||
y -= height;
|
||||
}
|
||||
|
||||
return GenerateImageID(punkImage, max(1.0, width), max(1.0, height));
|
||||
}
|
||||
CImageInfo WriteImage(CString& strFile, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
CImageInfo info;
|
||||
CFile oFile;
|
||||
if (S_OK != oFile.OpenFile(strFile))
|
||||
return info;
|
||||
|
||||
oFile.CloseFile();
|
||||
return GenerateImageID(strFile, max(1.0, width), max(1.0, height));
|
||||
}
|
||||
|
||||
protected:
|
||||
inline void CopyFile(CString& strFileSrc, CString& strFileDst)
|
||||
{
|
||||
CDirectory::CopyFile(strFileSrc, strFileDst, NULL, NULL);
|
||||
}
|
||||
void SaveImage(CString& strFileSrc, CImageInfo& oInfo, LONG __width, LONG __height)
|
||||
{
|
||||
CString strLoadXml = _T("<transforms><ImageFile-LoadImage sourcepath=\"") + strFileSrc + _T("\"/></transforms>");
|
||||
|
||||
ImageStudio::IImageTransforms* pTransform = NULL;
|
||||
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("");
|
||||
|
||||
LONG lMaxSize = min(max(__width, __height), m_lMaxSizeImage);
|
||||
|
||||
if ((lWidth <= lMaxSize) && (lHeight <= lMaxSize))
|
||||
{
|
||||
strXml = _T("<transforms>") + strSaveItem + _T("</transforms>");
|
||||
}
|
||||
else
|
||||
{
|
||||
LONG lW = 0;
|
||||
LONG lH = 0;
|
||||
double dAspect = (double)lWidth / lHeight;
|
||||
|
||||
if (lWidth >= lHeight)
|
||||
{
|
||||
lW = lMaxSize;
|
||||
lH = (LONG)((double)lW / dAspect);
|
||||
}
|
||||
else
|
||||
{
|
||||
lH = lMaxSize;
|
||||
lW = (LONG)(dAspect * lH);
|
||||
}
|
||||
|
||||
CString strResize = _T("");
|
||||
strResize.Format(_T("<ImageTransform-TransformResize type=\"65536\" 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, LONG __width, LONG __height)
|
||||
{
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
if (NULL == pFrame)
|
||||
return;
|
||||
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
|
||||
oInfo.m_eType = GetImageType(pFrame);
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
|
||||
ImageStudio::IImageTransforms* pTransform = NULL;
|
||||
CoCreateInstance(ImageStudio::CLSID_ImageTransforms, NULL ,CLSCTX_INPROC_SERVER, ImageStudio::IID_IImageTransforms, (void**)&pTransform);
|
||||
|
||||
VARIANT var;
|
||||
var.vt = VT_UNKNOWN;
|
||||
var.punkVal = punkImage;
|
||||
pTransform->SetSource(0, var);
|
||||
|
||||
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\"/>");
|
||||
}
|
||||
|
||||
LONG lMaxSize = min(max(__width, __height), m_lMaxSizeImage);
|
||||
|
||||
CString strXml = _T("");
|
||||
if ((lWidth <= lMaxSize) && (lHeight <= lMaxSize))
|
||||
{
|
||||
strXml = _T("<transforms>") + strSaveItem + _T("</transforms>");
|
||||
}
|
||||
else
|
||||
{
|
||||
LONG lW = 0;
|
||||
LONG lH = 0;
|
||||
double dAspect = (double)lWidth / lHeight;
|
||||
|
||||
if (lWidth >= lHeight)
|
||||
{
|
||||
lW = lMaxSize;
|
||||
lH = (LONG)((double)lW / dAspect);
|
||||
}
|
||||
else
|
||||
{
|
||||
lH = lMaxSize;
|
||||
lW = (LONG)(dAspect * lH);
|
||||
}
|
||||
|
||||
CString strResize = _T("");
|
||||
strResize.Format(_T("<ImageTransform-TransformResize type=\"65536\" 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, double dWidth, double dHeight)
|
||||
{
|
||||
CImageInfo oInfo;
|
||||
|
||||
if (NULL == punkData)
|
||||
return oInfo;
|
||||
|
||||
LONG lWidth = (LONG)(dWidth * 96 / 25.4);
|
||||
LONG lHeight = (LONG)(dHeight * 96 / 25.4);
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkData->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
LONG lLen = 0;
|
||||
|
||||
pFrame->get_Buffer(&pBuffer);
|
||||
pFrame->get_BufferSize(&lLen);
|
||||
|
||||
DWORD dwSum = m_oCRC.Calc(pBuffer, lLen);
|
||||
|
||||
CAtlMap<DWORD, CImageInfo>::CPair* pPair = m_mapImageData.Lookup(dwSum);
|
||||
if (NULL == pPair)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
++m_lNextIDImage;
|
||||
|
||||
oInfo.m_lID = m_lNextIDImage;
|
||||
SaveImage(punkData, oInfo, lWidth, lHeight);
|
||||
m_mapImageData.SetAt(dwSum, oInfo);
|
||||
m_listImages.AddTail(oInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
oInfo = pPair->m_value;
|
||||
}
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
|
||||
return oInfo;
|
||||
}
|
||||
|
||||
CImageInfo GenerateImageID(CString& strFileName, double dWidth, double dHeight)
|
||||
{
|
||||
CImageInfo oInfo;
|
||||
CAtlMap<CString, CImageInfo>::CPair* pPair = m_mapImagesFile.Lookup(strFileName);
|
||||
|
||||
LONG lWidth = (LONG)(dWidth * 96 / 25.4);
|
||||
LONG lHeight = (LONG)(dHeight * 96 / 25.4);
|
||||
|
||||
if (NULL == pPair)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
++m_lNextIDImage;
|
||||
|
||||
oInfo.m_lID = m_lNextIDImage;
|
||||
SaveImage(strFileName, oInfo, lWidth, lHeight);
|
||||
m_mapImagesFile.SetAt(strFileName, oInfo);
|
||||
m_listImages.AddTail(oInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
oInfo = pPair->m_value;
|
||||
}
|
||||
|
||||
return oInfo;
|
||||
}
|
||||
|
||||
ImageType GetImageType(MediaCore::IAVSUncompressedVideoFrame* pFrame)
|
||||
{
|
||||
if (2 == m_lDstFormat)
|
||||
return itJPG;
|
||||
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
BYTE* pBuffer = NULL;
|
||||
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
pFrame->get_Buffer(&pBuffer);
|
||||
|
||||
BYTE* pBufferMem = pBuffer + 3;
|
||||
LONG lCountPix = lWidth * lHeight;
|
||||
|
||||
for (LONG i = 0; i < lCountPix; ++i, pBufferMem += 4)
|
||||
{
|
||||
if (255 != *pBufferMem)
|
||||
return itPNG;
|
||||
}
|
||||
return itJPG;
|
||||
}
|
||||
|
||||
void FlipY(IUnknown* punkImage)
|
||||
{
|
||||
if (NULL == punkImage)
|
||||
return;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
if (NULL == pFrame)
|
||||
return;
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
LONG lWidth = 0;
|
||||
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)
|
||||
{
|
||||
RELEASEINTERFACE(pFrame);
|
||||
return;
|
||||
}
|
||||
|
||||
BYTE* pBufferMem = new BYTE[lStride];
|
||||
|
||||
BYTE* pBufferEnd = pBuffer + lStride * (lHeight - 1);
|
||||
|
||||
LONG lCountV = lHeight / 2;
|
||||
|
||||
for (LONG lIndexV = 0; lIndexV < lCountV; ++lIndexV)
|
||||
{
|
||||
memcpy(pBufferMem, pBuffer, lStride);
|
||||
memcpy(pBuffer, pBufferEnd, lStride);
|
||||
memcpy(pBufferEnd, pBufferMem, lStride);
|
||||
|
||||
pBuffer += lStride;
|
||||
pBufferEnd -= lStride;
|
||||
}
|
||||
|
||||
RELEASEARRAYOBJECTS(pBufferMem);
|
||||
RELEASEINTERFACE(pFrame);
|
||||
}
|
||||
|
||||
void FlipX(IUnknown* punkImage)
|
||||
{
|
||||
if (NULL == punkImage)
|
||||
return;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
if (NULL == pFrame)
|
||||
return;
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
LONG lWidth = 0;
|
||||
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)
|
||||
{
|
||||
RELEASEINTERFACE(pFrame);
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD* pBufferDWORD = (DWORD*)pBuffer;
|
||||
|
||||
LONG lW2 = lWidth / 2;
|
||||
for (LONG lIndexV = 0; lIndexV < lHeight; ++lIndexV)
|
||||
{
|
||||
DWORD* pMem1 = pBufferDWORD;
|
||||
DWORD* pMem2 = pBufferDWORD + lWidth - 1;
|
||||
|
||||
LONG lI = 0;
|
||||
while (lI < lW2)
|
||||
{
|
||||
DWORD dwMem = *pMem1;
|
||||
*pMem1++ = *pMem2;
|
||||
*pMem2-- = dwMem;
|
||||
}
|
||||
}
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
// 2-byte number
|
||||
AVSINLINE short little_endian_2_big_endian( short s )
|
||||
{
|
||||
return ( ( s >> 8) & 0xff ) + ( ( s << 8 ) & 0xff00 );
|
||||
}
|
||||
|
||||
/*========================================================================================================*/
|
||||
|
||||
// 4-byte number
|
||||
AVSINLINE int little_endian_2_big_endian( int i )
|
||||
{
|
||||
return ( ( i & 0xff ) << 24 ) + ( ( i & 0xff00 ) << 8 ) + ( ( i & 0xff0000 ) >> 8 ) + ( ( i >> 24 ) & 0xff );
|
||||
}
|
||||
|
||||
AVSINLINE CString ToHexString( unsigned int ui )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/*========================================================================================================*/
|
||||
}
|
||||
460
AVSEBOOKWriter/Common/File.h
Normal file
460
AVSEBOOKWriter/Common/File.h
Normal file
@ -0,0 +1,460 @@
|
||||
#pragma once
|
||||
#include "windows.h"
|
||||
|
||||
class CFile
|
||||
{
|
||||
public:
|
||||
CFile()
|
||||
{
|
||||
m_hFileHandle = NULL;
|
||||
m_lFileSize = 0;
|
||||
m_lFilePosition = 0;
|
||||
}
|
||||
|
||||
virtual ~CFile()
|
||||
{
|
||||
CloseFile();
|
||||
}
|
||||
|
||||
virtual HRESULT OpenFile(CString FileName)
|
||||
{
|
||||
CloseFile();
|
||||
|
||||
HRESULT hRes = S_OK;
|
||||
DWORD AccessMode = GENERIC_READ;
|
||||
DWORD ShareMode = FILE_SHARE_READ;
|
||||
DWORD Disposition = OPEN_EXISTING;
|
||||
m_hFileHandle = ::CreateFile(FileName, AccessMode, ShareMode, NULL, Disposition, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
if (NULL == m_hFileHandle || INVALID_HANDLE_VALUE == m_hFileHandle)
|
||||
hRes = S_FALSE;
|
||||
else
|
||||
{
|
||||
ULARGE_INTEGER nTempSize;
|
||||
nTempSize.LowPart = ::GetFileSize(m_hFileHandle, &nTempSize.HighPart);
|
||||
m_lFileSize = nTempSize.QuadPart;
|
||||
|
||||
SetPosition(0);
|
||||
}
|
||||
|
||||
return hRes;
|
||||
}
|
||||
|
||||
virtual HRESULT OpenFileRW(CString FileName)
|
||||
{
|
||||
CloseFile();
|
||||
|
||||
HRESULT hRes = S_OK;
|
||||
DWORD AccessMode = GENERIC_READ | GENERIC_WRITE;
|
||||
DWORD ShareMode = FILE_SHARE_READ;
|
||||
DWORD Disposition = OPEN_EXISTING;
|
||||
m_hFileHandle = ::CreateFile(FileName, AccessMode, ShareMode, NULL, Disposition, 0, 0);
|
||||
|
||||
if (NULL == m_hFileHandle || INVALID_HANDLE_VALUE == m_hFileHandle)
|
||||
{
|
||||
hRes = S_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ULARGE_INTEGER nTempSize;
|
||||
nTempSize.LowPart = ::GetFileSize(m_hFileHandle, &nTempSize.HighPart);
|
||||
m_lFileSize = nTempSize.QuadPart;
|
||||
|
||||
SetPosition(0);
|
||||
}
|
||||
|
||||
return hRes;
|
||||
}
|
||||
|
||||
HRESULT ReadFile(BYTE* pData, DWORD nBytesToRead)
|
||||
{
|
||||
DWORD nBytesRead = 0;
|
||||
if(NULL == pData)
|
||||
return S_FALSE;
|
||||
|
||||
if(m_hFileHandle && (pData))
|
||||
{
|
||||
SetPosition(m_lFilePosition);
|
||||
::ReadFile(m_hFileHandle, pData, nBytesToRead, &nBytesRead, NULL);
|
||||
m_lFilePosition += nBytesRead;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT ReadFile2(BYTE* pData, DWORD nBytesToRead)
|
||||
{
|
||||
DWORD nBytesRead = 0;
|
||||
if(NULL == pData)
|
||||
return S_FALSE;
|
||||
|
||||
if(m_hFileHandle && (pData))
|
||||
{
|
||||
SetPosition(m_lFilePosition);
|
||||
::ReadFile(m_hFileHandle, pData, nBytesToRead, &nBytesRead, NULL);
|
||||
m_lFilePosition += nBytesRead;
|
||||
|
||||
for (size_t index = 0; index < nBytesToRead / 2; ++index)
|
||||
{
|
||||
BYTE temp = pData[index];
|
||||
pData[index] = pData[nBytesToRead - index - 1];
|
||||
pData[nBytesToRead - index - 1] = temp;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT ReadFile3(void* pData, DWORD nBytesToRead)
|
||||
{
|
||||
DWORD nBytesRead = 0;
|
||||
if(NULL == pData)
|
||||
return S_FALSE;
|
||||
|
||||
if(m_hFileHandle && (pData))
|
||||
{
|
||||
SetPosition(m_lFilePosition);
|
||||
::ReadFile(m_hFileHandle, pData, nBytesToRead, &nBytesRead, NULL);
|
||||
m_lFilePosition += nBytesRead;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
CString ReadStringFromUTF8(DWORD nLength)
|
||||
{
|
||||
BYTE* pData = new BYTE[nLength];
|
||||
this->ReadFile(pData, nLength);
|
||||
CString strRes = GetCStringFromUTF8(pData, nLength);
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
return strRes;
|
||||
}
|
||||
DWORD ReadDWORD()
|
||||
{
|
||||
DWORD dwVal = 0;
|
||||
this->ReadFile2((BYTE*)&dwVal, 4);
|
||||
return dwVal;
|
||||
}
|
||||
BYTE ReadBYTE()
|
||||
{
|
||||
BYTE dwVal = 0;
|
||||
this->ReadFile2(&dwVal, 1);
|
||||
return dwVal;
|
||||
}
|
||||
|
||||
static CString GetCStringFromUTF8( BYTE* pBuffer, LONG lCount, BOOL bIsRemoveCode = FALSE )
|
||||
{
|
||||
if (bIsRemoveCode)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>...
|
||||
while (('>' != *pBuffer) && (lCount > 0))
|
||||
{
|
||||
++pBuffer;
|
||||
--lCount;
|
||||
}
|
||||
++pBuffer;
|
||||
--lCount;
|
||||
}
|
||||
|
||||
LONG lLenght = 0;
|
||||
|
||||
TCHAR* pUnicodeString = new TCHAR[lCount + 1];
|
||||
LONG lIndexUnicode = 0;
|
||||
|
||||
for (LONG lIndex = 0; lIndex < lCount; ++lIndex)
|
||||
{
|
||||
if (0x00 == (0x80 & pBuffer[lIndex]))
|
||||
{
|
||||
//strRes += (TCHAR)pBuffer[lIndex];
|
||||
pUnicodeString[lIndexUnicode++] = (WCHAR)pBuffer[lIndex];
|
||||
continue;
|
||||
}
|
||||
else if (0x00 == (0x20 & pBuffer[lIndex]))
|
||||
{
|
||||
TCHAR mem = (TCHAR)(((pBuffer[lIndex] & 0x1F) << 6) + (pBuffer[lIndex + 1] & 0x3F));
|
||||
|
||||
//strRes += mem;
|
||||
pUnicodeString[lIndexUnicode++] = mem;
|
||||
|
||||
lIndex += 1;
|
||||
}
|
||||
else if (0x00 == (0x10 & pBuffer[lIndex]))
|
||||
{
|
||||
TCHAR mem = (TCHAR)(((pBuffer[lIndex] & 0x0F) << 12) + ((pBuffer[lIndex + 1] & 0x3F) << 6) + (pBuffer[lIndex + 2] & 0x3F));
|
||||
|
||||
//strRes += mem;
|
||||
pUnicodeString[lIndexUnicode++] = mem;
|
||||
|
||||
lIndex += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
BYTE mem = pBuffer[lIndex];
|
||||
//pUnicodeString[lIndexUnicode++] = mem;
|
||||
}
|
||||
}
|
||||
|
||||
pUnicodeString[lIndexUnicode] = 0;
|
||||
|
||||
CString strRes = (CString)pUnicodeString;
|
||||
RELEASEARRAYOBJECTS(pUnicodeString);
|
||||
|
||||
return strRes;
|
||||
}
|
||||
|
||||
HRESULT WriteFile(void* pData, DWORD nBytesToWrite)
|
||||
{
|
||||
if(m_hFileHandle)
|
||||
{
|
||||
DWORD dwWritten = 0;
|
||||
::WriteFile(m_hFileHandle, pData, nBytesToWrite, &dwWritten, NULL);
|
||||
m_lFilePosition += nBytesToWrite;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT WriteFile2(void* pData, DWORD nBytesToWrite)
|
||||
{
|
||||
if(m_hFileHandle)
|
||||
{
|
||||
BYTE* mem = new BYTE[nBytesToWrite];
|
||||
memcpy(mem, pData, nBytesToWrite);
|
||||
|
||||
for (size_t index = 0; index < nBytesToWrite / 2; ++index)
|
||||
{
|
||||
BYTE temp = mem[index];
|
||||
mem[index] = mem[nBytesToWrite - index - 1];
|
||||
mem[nBytesToWrite - index - 1] = temp;
|
||||
}
|
||||
|
||||
DWORD dwWritten = 0;
|
||||
::WriteFile(m_hFileHandle, (void*)mem, nBytesToWrite, &dwWritten, NULL);
|
||||
m_lFilePosition += nBytesToWrite;
|
||||
RELEASEARRAYOBJECTS(mem);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CreateFile(CString strFileName)
|
||||
{
|
||||
CloseFile();
|
||||
DWORD AccessMode = GENERIC_WRITE;
|
||||
DWORD ShareMode = FILE_SHARE_WRITE;
|
||||
DWORD Disposition = CREATE_ALWAYS;
|
||||
m_hFileHandle = ::CreateFile(strFileName, AccessMode, ShareMode, NULL, Disposition, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
return SetPosition(0);
|
||||
}
|
||||
HRESULT SetPosition( ULONG64 nPos )
|
||||
{
|
||||
if (m_hFileHandle && nPos < (ULONG)m_lFileSize)
|
||||
{
|
||||
LARGE_INTEGER nTempPos;
|
||||
nTempPos.QuadPart = nPos;
|
||||
::SetFilePointer(m_hFileHandle, nTempPos.LowPart, &nTempPos.HighPart, FILE_BEGIN);
|
||||
m_lFilePosition = nPos;
|
||||
return S_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (INVALID_HANDLE_VALUE == m_hFileHandle) ? S_FALSE : S_OK;
|
||||
}
|
||||
}
|
||||
LONG64 GetPosition()
|
||||
{
|
||||
return m_lFilePosition;
|
||||
}
|
||||
HRESULT SkipBytes(ULONG64 nCount)
|
||||
{
|
||||
return SetPosition(m_lFilePosition + nCount);
|
||||
}
|
||||
|
||||
HRESULT CloseFile()
|
||||
{
|
||||
m_lFileSize = 0;
|
||||
m_lFilePosition = 0;
|
||||
RELEASEHANDLE(m_hFileHandle);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
ULONG64 GetFileSize()
|
||||
{
|
||||
return m_lFileSize;
|
||||
}
|
||||
|
||||
HRESULT WriteReserved(DWORD dwCount)
|
||||
{
|
||||
BYTE* buf = new BYTE[dwCount];
|
||||
memset(buf, 0, (size_t)dwCount);
|
||||
HRESULT hr = WriteFile(buf, dwCount);
|
||||
RELEASEARRAYOBJECTS(buf);
|
||||
return hr;
|
||||
}
|
||||
HRESULT WriteReserved2(DWORD dwCount)
|
||||
{
|
||||
BYTE* buf = new BYTE[dwCount];
|
||||
memset(buf, 0xFF, (size_t)dwCount);
|
||||
HRESULT hr = WriteFile(buf, dwCount);
|
||||
RELEASEARRAYOBJECTS(buf);
|
||||
return hr;
|
||||
}
|
||||
HRESULT WriteReservedTo(DWORD dwPoint)
|
||||
{
|
||||
if (m_lFilePosition >= dwPoint)
|
||||
return S_OK;
|
||||
|
||||
DWORD dwCount = dwPoint - (DWORD)m_lFilePosition;
|
||||
BYTE* buf = new BYTE[dwCount];
|
||||
memset(buf, 0, (size_t)dwCount);
|
||||
HRESULT hr = WriteFile(buf, dwCount);
|
||||
RELEASEARRAYOBJECTS(buf);
|
||||
return hr;
|
||||
}
|
||||
HRESULT SkipReservedTo(DWORD dwPoint)
|
||||
{
|
||||
if (m_lFilePosition >= dwPoint)
|
||||
return S_OK;
|
||||
|
||||
DWORD dwCount = dwPoint - (DWORD)m_lFilePosition;
|
||||
return SkipBytes(dwCount);
|
||||
}
|
||||
|
||||
LONG GetProgress()
|
||||
{
|
||||
if (0 >= m_lFileSize)
|
||||
return -1;
|
||||
|
||||
double dVal = (double)(100 * m_lFilePosition);
|
||||
LONG lProgress = (LONG)(dVal / m_lFileSize);
|
||||
return lProgress;
|
||||
}
|
||||
|
||||
void WriteStringUTF8(CString& strXml)
|
||||
{
|
||||
int nLength = strXml.GetLength();
|
||||
|
||||
CStringA saStr;
|
||||
|
||||
#ifdef UNICODE
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, strXml.GetBuffer(), nLength + 1, saStr.GetBuffer(nLength*3 + 1), nLength*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
#else
|
||||
wchar_t* pWStr = new wchar_t[nLength + 1];
|
||||
if (!pWStr)
|
||||
return;
|
||||
|
||||
// set end string
|
||||
pWStr[nLength] = 0;
|
||||
|
||||
// Encoding ASCII to Unicode
|
||||
MultiByteToWideChar(CP_ACP, 0, strXml, nLength, pWStr, nLength);
|
||||
|
||||
int nLengthW = (int)wcslen(pWStr);
|
||||
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, pWStr, nLengthW + 1, saStr.GetBuffer(nLengthW*3 + 1), nLengthW*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
|
||||
delete[] pWStr;
|
||||
#endif
|
||||
|
||||
WriteFile((void*)saStr.GetBuffer(), saStr.GetLength());
|
||||
}
|
||||
|
||||
protected:
|
||||
HANDLE m_hFileHandle;
|
||||
LONG64 m_lFileSize;
|
||||
LONG64 m_lFilePosition;
|
||||
};
|
||||
|
||||
namespace CDirectory
|
||||
{
|
||||
static CString GetFolderName(CString strFolderPath)
|
||||
{
|
||||
int n1 = strFolderPath.ReverseFind('\\');
|
||||
if (-1 == n1)
|
||||
return _T("");
|
||||
|
||||
return strFolderPath.Mid(n1 + 1);
|
||||
}
|
||||
static BOOL OpenFile(CString strFolderPath, CString strFileName, CFile* pFile)
|
||||
{
|
||||
CString strFile = strFolderPath + '\\' + strFileName;
|
||||
return (S_OK == pFile->OpenFile(strFile));
|
||||
}
|
||||
static BOOL CreateFile(CString strFolderPath, CString strFileName, CFile* pFile)
|
||||
{
|
||||
CString strFile = strFolderPath + '\\' + strFileName;
|
||||
return (S_OK == pFile->CreateFile(strFile));
|
||||
}
|
||||
static BOOL CreateDirectory(CString strFolderPathRoot, CString strFolderName)
|
||||
{
|
||||
CString strFolder = strFolderPathRoot + '\\' + strFolderName;
|
||||
return ::CreateDirectory(strFolder, NULL);
|
||||
}
|
||||
static BOOL CreateDirectory(CString strFolderPath)
|
||||
{
|
||||
return ::CreateDirectory(strFolderPath, NULL);
|
||||
}
|
||||
|
||||
static BOOL MoveFile(CString strExists, CString strNew, LPPROGRESS_ROUTINE lpFunc, LPVOID lpData)
|
||||
{
|
||||
#if (_WIN32_WINNT >= 0x0500)
|
||||
return ::MoveFileWithProgress(strExists, strNew, lpFunc, lpData, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
|
||||
#else
|
||||
return ::MoveFileEx(strExists, strNew, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
|
||||
#endif
|
||||
}
|
||||
|
||||
static BOOL CopyFile(CString strExists, CString strNew, LPPROGRESS_ROUTINE lpFunc, LPVOID lpData)
|
||||
{
|
||||
DeleteFile(strNew);
|
||||
return ::CopyFileEx(strExists, strNew, lpFunc, lpData, FALSE, 0);
|
||||
}
|
||||
|
||||
static CString GetUnder(CString strFolderPathRoot, CString strFolderName)
|
||||
{
|
||||
CString strFolder = strFolderPathRoot + '\\' + strFolderName;
|
||||
return strFolder;
|
||||
}
|
||||
|
||||
static CString GetFileName(CString strFullName)
|
||||
{
|
||||
int nStart = strFullName.ReverseFind('\\');
|
||||
CString strName = strFullName.Mid(nStart + 1);
|
||||
return strName;
|
||||
}
|
||||
|
||||
static void SaveToFile(CString strFileName, CString strXml)
|
||||
{
|
||||
int nLength = strXml.GetLength();
|
||||
|
||||
CStringA saStr;
|
||||
|
||||
#ifdef UNICODE
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, strXml.GetBuffer(), nLength + 1, saStr.GetBuffer(nLength*3 + 1), nLength*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
#else
|
||||
wchar_t* pWStr = new wchar_t[nLength + 1];
|
||||
if (!pWStr)
|
||||
return;
|
||||
|
||||
// set end string
|
||||
pWStr[nLength] = 0;
|
||||
|
||||
// Encoding ASCII to Unicode
|
||||
MultiByteToWideChar(CP_ACP, 0, strXml, nLength, pWStr, nLength);
|
||||
|
||||
int nLengthW = (int)wcslen(pWStr);
|
||||
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, pWStr, nLengthW + 1, saStr.GetBuffer(nLengthW*3 + 1), nLengthW*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
|
||||
delete[] pWStr;
|
||||
#endif
|
||||
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strFileName);
|
||||
oFile.WriteFile((void*)saStr.GetBuffer(), saStr.GetLength());
|
||||
oFile.CloseFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
269
AVSEBOOKWriter/Common/FontManager.h
Normal file
269
AVSEBOOKWriter/Common/FontManager.h
Normal file
@ -0,0 +1,269 @@
|
||||
#pragma once
|
||||
#include "Common.h"
|
||||
#include "FontManagerBase.h"
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
using namespace NSFontManager;
|
||||
|
||||
const double c_dDpiX = 72.0;
|
||||
const double c_dDpiY = 72.0;
|
||||
|
||||
class CFontManager : public CFontManagerBase
|
||||
{
|
||||
public:
|
||||
NSStructures::CFont* m_pFont;
|
||||
NSCommon::CMatrix* m_pTransform;
|
||||
|
||||
double m_dSpaceWidthMM;
|
||||
|
||||
public:
|
||||
CFontManager() : m_pFont(NULL), CFontManagerBase()
|
||||
{
|
||||
m_pTransform = NULL;
|
||||
m_dSpaceWidthMM = 0;
|
||||
}
|
||||
virtual ~CFontManager()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void LoadFont(long lFaceIndex = 0, bool bIsNeedAddToMap = true)
|
||||
{
|
||||
if (NULL == m_pManager)
|
||||
return;
|
||||
|
||||
double dSize = m_pFont->Size;
|
||||
double dSizeFont = dSize * ((m_pTransform->m_agg_mtx.sx + m_pTransform->m_agg_mtx.sy) / 2);
|
||||
|
||||
m_pFont->Size = dSizeFont;
|
||||
|
||||
if (m_pFont->IsEqual2(&m_oFont.m_oFont))
|
||||
{
|
||||
m_pFont->Size = dSize;
|
||||
return;
|
||||
}
|
||||
|
||||
m_oFont.m_oFont = *m_pFont;
|
||||
m_pFont->Size = dSize;
|
||||
|
||||
bool bIsPath = false;
|
||||
|
||||
if (_T("") == m_pFont->Path)
|
||||
{
|
||||
CFontManagerBase::LoadFontByName(m_oFont.m_oFont.Name, m_oFont.m_oFont.Size, m_oFont.m_oFont.GetStyle());
|
||||
}
|
||||
else
|
||||
{
|
||||
CFontManagerBase::LoadFontByFile(m_oFont.m_oFont.Path, m_oFont.m_oFont.Size, lFaceIndex);
|
||||
|
||||
m_pFont->SetStyle(m_oFont.m_oProperties.m_lStyle);
|
||||
m_oFont.m_oFont.SetStyle(m_oFont.m_oProperties.m_lStyle);
|
||||
|
||||
bIsPath = true;
|
||||
}
|
||||
|
||||
CalculateSpace();
|
||||
}
|
||||
|
||||
AVSINLINE void CalculateSpace()
|
||||
{
|
||||
LONG lGid = 0;
|
||||
m_pManager->GetStringGID(&lGid);
|
||||
m_pManager->SetStringGID(FALSE);
|
||||
|
||||
m_pManager->LoadString(L" ", 0, 0);
|
||||
float _x = 0;
|
||||
float _y = 0;
|
||||
float _w = 0;
|
||||
float _h = 0;
|
||||
|
||||
m_pManager->MeasureString2(&_x, &_y, &_w, &_h);
|
||||
|
||||
m_dSpaceWidthMM = (double)_w * c_dPixToMM;
|
||||
if (0 >= m_dSpaceWidthMM)
|
||||
{
|
||||
m_dSpaceWidthMM = 1.0;
|
||||
}
|
||||
|
||||
m_pManager->SetStringGID(lGid);
|
||||
}
|
||||
};
|
||||
|
||||
class CFontDstGenerator
|
||||
{
|
||||
public:
|
||||
NSStructures::CFont* m_pFonts;
|
||||
LONG m_lCurrentIndex;
|
||||
LONG m_lCountFonts;
|
||||
LONG m_lSize;
|
||||
|
||||
public:
|
||||
CFontDstGenerator()
|
||||
{
|
||||
m_lSize = 50;
|
||||
m_pFonts = NULL;
|
||||
m_lCurrentIndex = -1;
|
||||
m_lCountFonts = 0;
|
||||
|
||||
Grow();
|
||||
}
|
||||
~CFontDstGenerator()
|
||||
{
|
||||
RELEASEARRAYOBJECTS(m_pFonts);
|
||||
}
|
||||
public:
|
||||
LONG AddFont(NSStructures::CFont* pFont, BOOL bIsFontChanged, CFontManagerBase* pBase)
|
||||
{
|
||||
if (-1 != m_lCurrentIndex && !bIsFontChanged)
|
||||
return m_lCurrentIndex;
|
||||
|
||||
LONG lIndex = m_lCountFonts - 1;
|
||||
while (lIndex >= 0)
|
||||
{
|
||||
if (m_pFonts[lIndex].IsEqual4(pFont))
|
||||
break;
|
||||
--lIndex;
|
||||
}
|
||||
if (lIndex >= 0)
|
||||
{
|
||||
m_lCurrentIndex = lIndex;
|
||||
return m_lCurrentIndex;
|
||||
}
|
||||
|
||||
if (m_lCountFonts == m_lSize)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Grow();
|
||||
}
|
||||
|
||||
m_lCurrentIndex = m_lCountFonts;
|
||||
++m_lCountFonts;
|
||||
m_pFonts[m_lCurrentIndex] = *pFont;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>...
|
||||
m_pFonts[m_lCurrentIndex].Path = pBase->GetFontPath(&m_pFonts[m_lCurrentIndex]);
|
||||
return m_lCurrentIndex;
|
||||
}
|
||||
|
||||
LONG AddFont2(NSStructures::CFont* pFont, BOOL bIsFontChanged, CFontManagerBase* pBase)
|
||||
{
|
||||
if (-1 != m_lCurrentIndex && !bIsFontChanged)
|
||||
return m_lCurrentIndex;
|
||||
|
||||
CString strName = pFont->Name;
|
||||
LONG lStyle = pFont->GetStyle();
|
||||
|
||||
pFont->Name = pBase->m_strCurrentPickFont;
|
||||
pFont->SetStyle(pBase->m_lCurrentPictFontStyle);
|
||||
|
||||
LONG lIndex = m_lCountFonts - 1;
|
||||
while (lIndex >= 0)
|
||||
{
|
||||
if (m_pFonts[lIndex].IsEqual4(pFont))
|
||||
break;
|
||||
--lIndex;
|
||||
}
|
||||
if (lIndex >= 0)
|
||||
{
|
||||
m_lCurrentIndex = lIndex;
|
||||
|
||||
pFont->Name = strName;
|
||||
pFont->SetStyle(lStyle);
|
||||
|
||||
return m_lCurrentIndex;
|
||||
}
|
||||
|
||||
if (m_lCountFonts == m_lSize)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Grow();
|
||||
}
|
||||
|
||||
m_lCurrentIndex = m_lCountFonts;
|
||||
++m_lCountFonts;
|
||||
m_pFonts[m_lCurrentIndex] = *pFont;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>...
|
||||
m_pFonts[m_lCurrentIndex].Path = pBase->GetFontPath(&m_pFonts[m_lCurrentIndex]);
|
||||
|
||||
pFont->Name = strName;
|
||||
pFont->SetStyle(lStyle);
|
||||
|
||||
return m_lCurrentIndex;
|
||||
}
|
||||
|
||||
public:
|
||||
void WriteFonts(CString strFolderDst, CString& strCSS, CString& strItems)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> css
|
||||
strCSS = _T("");
|
||||
strItems = _T("");
|
||||
for (LONG nFont = 0; nFont < m_lCountFonts; ++nFont)
|
||||
{
|
||||
CString strName = m_pFonts[nFont].Name;
|
||||
strName.Replace(_T(" "), _T("_avs_space_"));
|
||||
|
||||
CString strCssMem = _T("@font-face {font-family:") + strName + _T(";font-weight:");
|
||||
if (m_pFonts[nFont].Bold)
|
||||
strCssMem += _T("bold;font-style:");
|
||||
else
|
||||
strCssMem += _T("normal;font-style:");
|
||||
|
||||
if (m_pFonts[nFont].Italic)
|
||||
strCssMem += _T("italic;src:url(fonts/");
|
||||
else
|
||||
strCssMem += _T("normal;src:url(fonts/");
|
||||
|
||||
int nStart1 = m_pFonts[nFont].Path.ReverseFind((TCHAR)'\\');
|
||||
int nStart2 = m_pFonts[nFont].Path.ReverseFind((TCHAR)'/');
|
||||
|
||||
int nStart = max(nStart1, nStart2);
|
||||
int nEnd = m_pFonts[nFont].Path.GetLength();
|
||||
|
||||
CString strDstName = m_pFonts[nFont].Path.Mid(nStart + 1, nEnd - nStart - 1);
|
||||
strDstName.Replace(_T(" "), _T("_avs_space_"));
|
||||
CString strFile = strFolderDst + _T("\\fonts\\") + strDstName;
|
||||
|
||||
DWORD dwFileAttrib = ::GetFileAttributes(strFile);
|
||||
if (dwFileAttrib == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
|
||||
::CopyFile(m_pFonts[nFont].Path, strFile, TRUE);
|
||||
}
|
||||
|
||||
nEnd = strDstName.Find(TCHAR('.'));
|
||||
CString strId = strDstName;
|
||||
if (-1 != nEnd)
|
||||
strId = strId.Mid(0, nEnd);
|
||||
|
||||
strItems += (_T("<item id=\"") + strId + _T("\" href=\"fonts/") + strDstName + _T("\" media-type=\"application/x-font-ttf\"/>"));
|
||||
|
||||
strCssMem += strDstName;
|
||||
strCssMem += _T(");}\n");
|
||||
|
||||
strCSS += strCssMem;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
void Grow()
|
||||
{
|
||||
if (NULL == m_pFonts)
|
||||
{
|
||||
m_pFonts = new NSStructures::CFont[m_lSize];
|
||||
return;
|
||||
}
|
||||
|
||||
NSStructures::CFont* pNewBuffer = new NSStructures::CFont[m_lSize * 2];
|
||||
for (LONG i = 0; i < m_lSize; ++i)
|
||||
{
|
||||
pNewBuffer[i] = m_pFonts[i];
|
||||
}
|
||||
RELEASEARRAYOBJECTS(m_pFonts);
|
||||
m_pFonts = pNewBuffer;
|
||||
|
||||
m_lSize *= 2;
|
||||
}
|
||||
};
|
||||
}
|
||||
173
AVSEBOOKWriter/Common/Matrix.h
Normal file
173
AVSEBOOKWriter/Common/Matrix.h
Normal file
@ -0,0 +1,173 @@
|
||||
#pragma once
|
||||
|
||||
#include "ap_AggPlusEnums.h"
|
||||
#include "ap_AggPlusTypes.h"
|
||||
#include "agg_trans_affine.h"
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
class CMatrix
|
||||
{
|
||||
public:
|
||||
CMatrix(double m11, double m12, double m21, double m22, double dx, double dy) : m_agg_mtx(m11, m12, m21, m22, dx, dy)
|
||||
{
|
||||
}
|
||||
|
||||
CMatrix() : m_agg_mtx()
|
||||
{
|
||||
}
|
||||
|
||||
~CMatrix()
|
||||
{
|
||||
}
|
||||
|
||||
void Translate(double offsetX, double offsetY, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_translation(offsetX, offsetY));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_translation(offsetX, offsetY));
|
||||
}
|
||||
}
|
||||
|
||||
void Scale(double scaleX, double scaleY, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_scaling(scaleX, scaleY));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_scaling(scaleX, scaleY));
|
||||
}
|
||||
}
|
||||
|
||||
void Shear(double shearX, double shearY, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_skewing(shearX, shearY));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_skewing(shearX, shearY));
|
||||
}
|
||||
}
|
||||
|
||||
void TransformPoint(double& x, double& y)
|
||||
{
|
||||
m_agg_mtx.transform(&x, &y);
|
||||
}
|
||||
|
||||
void Rotate(double angle, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
}
|
||||
|
||||
void RotateAt(double angle, double x, double y, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
Translate(-x, -y, order);
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
Translate(x, y, order);
|
||||
}
|
||||
|
||||
void Multiply(const CMatrix* matrix, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(matrix->m_agg_mtx);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(matrix->m_agg_mtx);
|
||||
}
|
||||
}
|
||||
|
||||
double OffsetX() const
|
||||
{
|
||||
double M[6]; m_agg_mtx.store_to(M);
|
||||
return (M[4]);
|
||||
}
|
||||
double OffsetY() const
|
||||
{
|
||||
double M[6]; m_agg_mtx.store_to(M);
|
||||
return (M[5]);
|
||||
}
|
||||
|
||||
bool GetElements(float* m) const
|
||||
{
|
||||
double M[6]; m_agg_mtx.store_to(M);
|
||||
m[0]=(float)M[0];
|
||||
m[1]=(float)M[1];
|
||||
m[2]=(float)M[2];
|
||||
m[3]=(float)M[3];
|
||||
m[4]=(float)M[4];
|
||||
m[5]=(float)M[5];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetElements(double* m) const
|
||||
{
|
||||
m_agg_mtx.store_to(m);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_agg_mtx.reset();
|
||||
}
|
||||
|
||||
const CMatrix& operator=(const CMatrix& Src)
|
||||
{
|
||||
m_agg_mtx = Src.m_agg_mtx;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Invert()
|
||||
{
|
||||
double d = m_agg_mtx.determinant();
|
||||
if (0.0001 >= abs(d))
|
||||
return false;
|
||||
|
||||
m_agg_mtx.invert();
|
||||
return true;
|
||||
}
|
||||
|
||||
//Temp
|
||||
//Used in X_BrushLinearGradient constructor
|
||||
double z_Rotation() const
|
||||
{
|
||||
return agg::rad2deg(m_agg_mtx.rotation());
|
||||
}
|
||||
|
||||
__forceinline void SetElements(const double& m11, const double& m12, const double& m21, const double& m22, const double& dx, const double& dy)
|
||||
{
|
||||
m_agg_mtx.sx = m11;
|
||||
m_agg_mtx.shy = m12;
|
||||
m_agg_mtx.shx = m21;
|
||||
m_agg_mtx.sy = m22;
|
||||
m_agg_mtx.tx = dx;
|
||||
m_agg_mtx.ty = dy;
|
||||
}
|
||||
|
||||
public:
|
||||
agg::trans_affine m_agg_mtx;
|
||||
};
|
||||
}
|
||||
746
AVSEBOOKWriter/Common/StringWriter.h
Normal file
746
AVSEBOOKWriter/Common/StringWriter.h
Normal file
@ -0,0 +1,746 @@
|
||||
#pragma once
|
||||
#include "File.h"
|
||||
|
||||
const double c_ag_Inch_to_MM = 25.4;
|
||||
const double c_ag_1pxWidth = 25.4 / 96;
|
||||
|
||||
static wchar_t g_wc_amp = wchar_t('&');
|
||||
static wchar_t g_wc_apos = wchar_t('\'');
|
||||
static wchar_t g_wc_lt = wchar_t('<');
|
||||
static wchar_t g_wc_qt = wchar_t('>');
|
||||
static wchar_t g_wc_quot = wchar_t('\"');
|
||||
|
||||
static _bstr_t g_bstr_amp = L"&";
|
||||
static _bstr_t g_bstr_apos = L"'";
|
||||
static _bstr_t g_bstr_lt = L"<";
|
||||
static _bstr_t g_bstr_qt = L">";
|
||||
static _bstr_t g_bstr_quot = L"\"";
|
||||
static _bstr_t g_bstr_mdash = L"—";
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
enum ImageType
|
||||
{
|
||||
itJPG = 0,
|
||||
itPNG = 1
|
||||
};
|
||||
class CImageInfo
|
||||
{
|
||||
public:
|
||||
ImageType m_eType;
|
||||
LONG m_lID;
|
||||
|
||||
CImageInfo()
|
||||
{
|
||||
m_eType = itJPG;
|
||||
m_lID = -1;
|
||||
}
|
||||
CImageInfo(const CImageInfo& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CImageInfo& operator=(const CImageInfo& oSrc)
|
||||
{
|
||||
m_eType = oSrc.m_eType;
|
||||
m_lID = oSrc.m_lID;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
AVSINLINE CString GetPath(const CString& strMedia)
|
||||
{
|
||||
CString strExt = _T("");
|
||||
strExt.Format(_T("\\image%d.%s"), m_lID, (itJPG == m_eType) ? _T("jpg") : _T("png"));
|
||||
return strMedia + strExt;
|
||||
}
|
||||
};
|
||||
|
||||
inline static double FABS(double dVal)
|
||||
{
|
||||
return (dVal >= 0) ? dVal : -dVal;
|
||||
}
|
||||
inline static int round(double dVal)
|
||||
{
|
||||
return (int)(dVal + 0.5);
|
||||
}
|
||||
|
||||
class CBufferedText
|
||||
{
|
||||
protected:
|
||||
BYTE* m_pData;
|
||||
size_t m_lSize;
|
||||
|
||||
BYTE* m_pDataCur;
|
||||
size_t m_lSizeCur;
|
||||
|
||||
public:
|
||||
CBufferedText()
|
||||
{
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = m_lSize;
|
||||
}
|
||||
CBufferedText(const CBufferedText& oSrc)
|
||||
{
|
||||
m_pData = NULL;
|
||||
*this = oSrc;
|
||||
}
|
||||
CBufferedText& operator=(const CBufferedText& oSrc)
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_lSize = oSrc.m_lSize;
|
||||
m_lSizeCur = oSrc.m_lSizeCur;
|
||||
m_pData = (BYTE*)malloc(m_lSize * sizeof(BYTE));
|
||||
|
||||
memcpy(m_pData, oSrc.m_pData, m_lSizeCur * sizeof(BYTE));
|
||||
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CBufferedText(const size_t& nLen)
|
||||
{
|
||||
m_lSize = nLen;
|
||||
m_pData = (BYTE*)malloc(m_lSize * sizeof(BYTE));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
}
|
||||
virtual ~CBufferedText()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
}
|
||||
|
||||
AVSINLINE void AddSize(const size_t& nSize)
|
||||
{
|
||||
if (NULL == m_pData)
|
||||
{
|
||||
m_lSize = max(nSize, 1000);
|
||||
m_pData = (BYTE*)malloc(m_lSize * sizeof(BYTE));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
while ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
m_lSize *= 2;
|
||||
}
|
||||
|
||||
BYTE* pRealloc = (BYTE*)realloc(m_pData, m_lSize * sizeof(BYTE));
|
||||
if (NULL != pRealloc)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
m_pData = pRealloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
else
|
||||
{
|
||||
BYTE* pMalloc = (BYTE*)malloc(m_lSize * sizeof(BYTE));
|
||||
memcpy(pMalloc, m_pData, m_lSizeCur * sizeof(BYTE));
|
||||
|
||||
free(m_pData);
|
||||
m_pData = pMalloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
AVSINLINE BYTE operator[](const size_t& nIndex)
|
||||
{
|
||||
if (nIndex < m_lSizeCur)
|
||||
return m_pData[nIndex];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
AVSINLINE void WriteData(BYTE* pString, const size_t& nLen)
|
||||
{
|
||||
AddSize(nLen);
|
||||
memcpy(m_pDataCur, pString, nLen);
|
||||
m_pDataCur += nLen;
|
||||
m_lSizeCur += nLen;
|
||||
}
|
||||
AVSINLINE BYTE* GetData()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
AVSINLINE size_t GetCurSize()
|
||||
{
|
||||
return m_lSizeCur;
|
||||
}
|
||||
AVSINLINE size_t GetSize()
|
||||
{
|
||||
return m_lSize;
|
||||
}
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
AVSINLINE void ClearNoAttack()
|
||||
{
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class CTextItem
|
||||
{
|
||||
protected:
|
||||
wchar_t* m_pData;
|
||||
size_t m_lSize;
|
||||
|
||||
wchar_t* m_pDataCur;
|
||||
size_t m_lSizeCur;
|
||||
|
||||
public:
|
||||
CTextItem()
|
||||
{
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = m_lSize;
|
||||
}
|
||||
CTextItem(const CTextItem& oSrc)
|
||||
{
|
||||
m_pData = NULL;
|
||||
*this = oSrc;
|
||||
}
|
||||
CTextItem& operator=(const CTextItem& oSrc)
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_lSize = oSrc.m_lSize;
|
||||
m_lSizeCur = oSrc.m_lSizeCur;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
memcpy(m_pData, oSrc.m_pData, m_lSizeCur * sizeof(wchar_t));
|
||||
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CTextItem(const size_t& nLen)
|
||||
{
|
||||
m_lSize = nLen;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
}
|
||||
CTextItem(wchar_t* pData, const size_t& nLen)
|
||||
{
|
||||
m_lSize = nLen;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
memcpy(m_pData, pData, m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = m_lSize;
|
||||
m_pDataCur = m_pData + m_lSize;
|
||||
}
|
||||
CTextItem(wchar_t* pData, BYTE* pUnicodeChecker = NULL)
|
||||
{
|
||||
size_t nLen = GetStringLen(pData);
|
||||
|
||||
m_lSize = nLen;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
memcpy(m_pData, pData, m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = m_lSize;
|
||||
m_pDataCur = m_pData + m_lSize;
|
||||
|
||||
if (NULL != pUnicodeChecker)
|
||||
{
|
||||
wchar_t* pMemory = m_pData;
|
||||
while (pMemory < m_pDataCur)
|
||||
{
|
||||
if (!pUnicodeChecker[*pMemory])
|
||||
*pMemory = wchar_t(' ');
|
||||
++pMemory;
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual ~CTextItem()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
}
|
||||
|
||||
AVSINLINE void AddSize(const size_t& nSize)
|
||||
{
|
||||
if (NULL == m_pData)
|
||||
{
|
||||
m_lSize = max(nSize, 1000);
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
while ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
m_lSize *= 2;
|
||||
}
|
||||
|
||||
wchar_t* pRealloc = (wchar_t*)realloc(m_pData, m_lSize * sizeof(wchar_t));
|
||||
if (NULL != pRealloc)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
m_pData = pRealloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t* pMalloc = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
memcpy(pMalloc, m_pData, m_lSizeCur * sizeof(wchar_t));
|
||||
|
||||
free(m_pData);
|
||||
m_pData = pMalloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AVSINLINE wchar_t* GetData()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
AVSINLINE size_t GetCurSize()
|
||||
{
|
||||
return m_lSizeCur;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
AVSINLINE void operator+=(const CTextItem& oTemp)
|
||||
{
|
||||
WriteString(oTemp.m_pData, oTemp.m_lSizeCur);
|
||||
}
|
||||
AVSINLINE void operator+=(_bstr_t& oTemp)
|
||||
{
|
||||
size_t nLen = oTemp.length();
|
||||
WriteString(oTemp.GetBSTR(), nLen);
|
||||
}
|
||||
AVSINLINE void operator+=(CString& oTemp)
|
||||
{
|
||||
size_t nLen = (size_t)oTemp.GetLength();
|
||||
|
||||
#ifdef _UNICODE
|
||||
WriteString(oTemp.GetBuffer(), nLen);
|
||||
#else
|
||||
CStringW str = (CStringW)oTemp;
|
||||
WriteString(str.GetBuffer(), nLen);
|
||||
#endif
|
||||
}
|
||||
AVSINLINE wchar_t& operator[](const size_t& nIndex)
|
||||
{
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
AVSINLINE void SetText(BSTR& bsText)
|
||||
{
|
||||
ClearNoAttack();
|
||||
size_t nLen = GetStringLen(bsText);
|
||||
|
||||
WriteString(bsText, nLen);
|
||||
}
|
||||
AVSINLINE void AddSpace()
|
||||
{
|
||||
AddSize(1);
|
||||
*m_pDataCur = wchar_t(' ');
|
||||
|
||||
++m_lSizeCur;
|
||||
++m_pDataCur;
|
||||
}
|
||||
AVSINLINE void AddSpaceFirst()
|
||||
{
|
||||
AddSize(1);
|
||||
|
||||
wchar_t* pMemory = new wchar_t[m_lSizeCur];
|
||||
memcpy(pMemory, m_pData, m_lSizeCur * sizeof(wchar_t));
|
||||
memcpy(m_pData + 1, pMemory, m_lSizeCur * sizeof(wchar_t));
|
||||
RELEASEARRAYOBJECTS(pMemory);
|
||||
|
||||
*m_pData = wchar_t(' ');
|
||||
|
||||
++m_lSizeCur;
|
||||
++m_pDataCur;
|
||||
}
|
||||
AVSINLINE BOOL IsEqual(const CTextItem& oItem)const
|
||||
{
|
||||
const wchar_t* pNew = oItem.m_pData;
|
||||
for (size_t i = 0; i < m_lSizeCur; ++i)
|
||||
{
|
||||
if (m_pData[i] != pNew[i])
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
AVSINLINE BOOL IsEqualLast(CTextItem& oItem, BOOL bIsAddSpace)const
|
||||
{
|
||||
if (bIsAddSpace != TRUE)
|
||||
return FALSE;
|
||||
|
||||
size_t size_cur = m_lSizeCur;
|
||||
size_t size_item = oItem.m_lSizeCur;
|
||||
wchar_t* p1 = m_pData;
|
||||
wchar_t* p2 = oItem.m_pData;
|
||||
for (size_t i = m_lSizeCur - 1; i >= 0; --i)
|
||||
{
|
||||
if (WCHAR(' ') != p1[i])
|
||||
break;
|
||||
--size_cur;
|
||||
}
|
||||
for (size_t i = oItem.m_lSizeCur - 1; i >= 0; --i)
|
||||
{
|
||||
if (WCHAR(' ') != p2[i])
|
||||
break;
|
||||
--size_item;
|
||||
}
|
||||
size_t len = min(size_cur, size_item);
|
||||
p1 = m_pData + size_cur - len;
|
||||
p2 = oItem.m_pData + size_item - len;
|
||||
for (size_t i = 0; i < len; ++i, ++p1, ++p2)
|
||||
if (*p1 != *p2)
|
||||
return FALSE;
|
||||
|
||||
if (bIsAddSpace && (size_cur != m_lSizeCur) && (size_item == oItem.m_lSizeCur))
|
||||
oItem.AddSpace();
|
||||
return TRUE;
|
||||
}
|
||||
AVSINLINE void CorrectUnicode(const BYTE* pUnicodeChecker)
|
||||
{
|
||||
if (NULL != pUnicodeChecker)
|
||||
{
|
||||
wchar_t* pMemory = m_pData;
|
||||
while (pMemory < m_pDataCur)
|
||||
{
|
||||
if (!pUnicodeChecker[*pMemory])
|
||||
*pMemory = wchar_t(' ');
|
||||
++pMemory;
|
||||
}
|
||||
}
|
||||
}
|
||||
AVSINLINE void RemoveLastSpaces()
|
||||
{
|
||||
wchar_t* pMemory = m_pDataCur - 1;
|
||||
while ((pMemory > m_pData) && (wchar_t(' ') == *pMemory))
|
||||
{
|
||||
--pMemory;
|
||||
--m_lSizeCur;
|
||||
--m_pDataCur;
|
||||
}
|
||||
|
||||
}
|
||||
AVSINLINE bool IsSpace()
|
||||
{
|
||||
if (1 != m_lSizeCur)
|
||||
return false;
|
||||
return (wchar_t(' ') == *m_pData);
|
||||
}
|
||||
AVSINLINE void CheckLastSpanLine()
|
||||
{
|
||||
if (0 == m_lSizeCur)
|
||||
return;
|
||||
|
||||
if ((wchar_t(' ') == m_pData[m_lSizeCur - 1]) || (wchar_t('-') == m_pData[m_lSizeCur - 1]))
|
||||
return;
|
||||
|
||||
AddSpace();
|
||||
}
|
||||
|
||||
public:
|
||||
AVSINLINE void WriteString(wchar_t* pString, const size_t& nLen)
|
||||
{
|
||||
AddSize(nLen);
|
||||
//memcpy(m_pDataCur, pString, nLen * sizeof(wchar_t));
|
||||
memcpy(m_pDataCur, pString, nLen << 1);
|
||||
m_pDataCur += nLen;
|
||||
m_lSizeCur += nLen;
|
||||
}
|
||||
AVSINLINE size_t GetSize()
|
||||
{
|
||||
return m_lSize;
|
||||
}
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
AVSINLINE void ClearNoAttack()
|
||||
{
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
|
||||
AVSINLINE size_t GetStringLen(wchar_t* pData)
|
||||
{
|
||||
wchar_t* s = pData;
|
||||
for (; *s != 0; ++s);
|
||||
return (size_t)(s - pData);
|
||||
}
|
||||
|
||||
AVSINLINE CString GetCString()
|
||||
{
|
||||
CString str(m_pData, (int)m_lSizeCur);
|
||||
return str;
|
||||
}
|
||||
AVSINLINE wchar_t* GetBuffer()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
};
|
||||
|
||||
class CStringWriter : public CTextItem
|
||||
{
|
||||
public:
|
||||
CStringWriter() : CTextItem()
|
||||
{
|
||||
}
|
||||
virtual ~CStringWriter()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
AVSINLINE void WriteStringB(_bstr_t& bsString)
|
||||
{
|
||||
size_t nLen = bsString.length();
|
||||
CTextItem::WriteString(bsString.GetBSTR(), nLen);
|
||||
}
|
||||
AVSINLINE void WriteString(CString sString)
|
||||
{
|
||||
size_t nLen = (size_t)sString.GetLength();
|
||||
|
||||
#ifdef _UNICODE
|
||||
CTextItem::WriteString(sString.GetBuffer(), nLen);
|
||||
#else
|
||||
CStringW str = (CStringW)sString;
|
||||
WriteString(str.GetBuffer(), nLen);
|
||||
#endif
|
||||
}
|
||||
AVSINLINE void WriteStringC(const CString& sString)
|
||||
{
|
||||
size_t nLen = (size_t)sString.GetLength();
|
||||
|
||||
CString* pStr = const_cast<CString*>(&sString);
|
||||
|
||||
#ifdef _UNICODE
|
||||
CTextItem::WriteString(pStr->GetBuffer(), nLen);
|
||||
#else
|
||||
CStringW str = (CStringW)sString;
|
||||
WriteString(str.GetBuffer(), nLen);
|
||||
#endif
|
||||
}
|
||||
AVSINLINE void Write(CStringWriter& oWriter)
|
||||
{
|
||||
CTextItem::WriteString(oWriter.m_pData, oWriter.m_lSizeCur);
|
||||
}
|
||||
AVSINLINE void WriteI(CTextItem& oItem)
|
||||
{
|
||||
CTextItem::WriteString(oItem.GetData(), oItem.GetCurSize());
|
||||
}
|
||||
|
||||
AVSINLINE void WriteString(wchar_t* pString, const size_t& nLen)
|
||||
{
|
||||
CTextItem::AddSize(nLen);
|
||||
//memcpy(m_pDataCur, pString, nLen * sizeof(wchar_t));
|
||||
memcpy(m_pDataCur, pString, nLen << 1);
|
||||
m_pDataCur += nLen;
|
||||
m_lSizeCur += nLen;
|
||||
}
|
||||
|
||||
void WriteTextHTML(CTextItem& oItem)
|
||||
{
|
||||
size_t nCurrent = 0;
|
||||
size_t nCount = oItem.GetCurSize();
|
||||
|
||||
size_t nCurrentOld = nCurrent;
|
||||
wchar_t* pData = oItem.GetData();
|
||||
wchar_t* pStartData = pData;
|
||||
|
||||
while (nCurrent < nCount)
|
||||
{
|
||||
wchar_t c = *pData++;
|
||||
|
||||
if (g_wc_amp == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_amp);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
/*else if (g_wc_apos == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_apos);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}*/
|
||||
else if (g_wc_lt == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_lt);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else if (g_wc_qt == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_qt);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else if (g_wc_quot == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_quot);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else if (8212 == (USHORT)c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_mdash);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else
|
||||
{
|
||||
++nCurrent;
|
||||
}
|
||||
}
|
||||
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
}
|
||||
|
||||
void WriteTextXML(CTextItem& oItem)
|
||||
{
|
||||
size_t nCurrent = 0;
|
||||
size_t nCount = oItem.GetCurSize();
|
||||
|
||||
size_t nCurrentOld = nCurrent;
|
||||
wchar_t* pData = oItem.GetData();
|
||||
wchar_t* pStartData = pData;
|
||||
|
||||
while (nCurrent < nCount)
|
||||
{
|
||||
wchar_t c = *pData++;
|
||||
|
||||
if (g_wc_amp == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_amp);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
/*else if (g_wc_apos == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_apos);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}*/
|
||||
else if (g_wc_lt == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_lt);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else if (g_wc_qt == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_qt);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else if (g_wc_quot == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_quot);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else
|
||||
{
|
||||
++nCurrent;
|
||||
}
|
||||
}
|
||||
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
}
|
||||
};
|
||||
}
|
||||
180
AVSEBOOKWriter/Common/agg_trans_affine.cpp
Normal file
180
AVSEBOOKWriter/Common/agg_trans_affine.cpp
Normal file
@ -0,0 +1,180 @@
|
||||
//
|
||||
// Affine transformations
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "agg_trans_affine.h"
|
||||
|
||||
|
||||
namespace agg
|
||||
{
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::parl_to_parl(const double* src,
|
||||
const double* dst)
|
||||
{
|
||||
sx = src[2] - src[0];
|
||||
shy = src[3] - src[1];
|
||||
shx = src[4] - src[0];
|
||||
sy = src[5] - src[1];
|
||||
tx = src[0];
|
||||
ty = src[1];
|
||||
invert();
|
||||
multiply(trans_affine(dst[2] - dst[0], dst[3] - dst[1],
|
||||
dst[4] - dst[0], dst[5] - dst[1],
|
||||
dst[0], dst[1]));
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::rect_to_parl(double x1, double y1,
|
||||
double x2, double y2,
|
||||
const double* parl)
|
||||
{
|
||||
double src[6];
|
||||
src[0] = x1; src[1] = y1;
|
||||
src[2] = x2; src[3] = y1;
|
||||
src[4] = x2; src[5] = y2;
|
||||
parl_to_parl(src, parl);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::parl_to_rect(const double* parl,
|
||||
double x1, double y1,
|
||||
double x2, double y2)
|
||||
{
|
||||
double dst[6];
|
||||
dst[0] = x1; dst[1] = y1;
|
||||
dst[2] = x2; dst[3] = y1;
|
||||
dst[4] = x2; dst[5] = y2;
|
||||
parl_to_parl(parl, dst);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::multiply(const trans_affine& m)
|
||||
{
|
||||
double t0 = sx * m.sx + shy * m.shx;
|
||||
double t2 = shx * m.sx + sy * m.shx;
|
||||
double t4 = tx * m.sx + ty * m.shx + m.tx;
|
||||
shy = sx * m.shy + shy * m.sy;
|
||||
sy = shx * m.shy + sy * m.sy;
|
||||
ty = tx * m.shy + ty * m.sy + m.ty;
|
||||
sx = t0;
|
||||
shx = t2;
|
||||
tx = t4;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::invert()
|
||||
{
|
||||
double d = determinant_reciprocal();
|
||||
|
||||
double t0 = sy * d;
|
||||
sy = sx * d;
|
||||
shy = -shy * d;
|
||||
shx = -shx * d;
|
||||
|
||||
double t4 = -tx * t0 - ty * shx;
|
||||
ty = -tx * shy - ty * sy;
|
||||
|
||||
sx = t0;
|
||||
tx = t4;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::flip_x()
|
||||
{
|
||||
sx = -sx;
|
||||
shy = -shy;
|
||||
tx = -tx;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::flip_y()
|
||||
{
|
||||
shx = -shx;
|
||||
sy = -sy;
|
||||
ty = -ty;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::reset()
|
||||
{
|
||||
sx = sy = 1.0;
|
||||
shy = shx = tx = ty = 0.0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
bool trans_affine::is_identity(double epsilon) const
|
||||
{
|
||||
return is_equal_eps(sx, 1.0, epsilon) &&
|
||||
is_equal_eps(shy, 0.0, epsilon) &&
|
||||
is_equal_eps(shx, 0.0, epsilon) &&
|
||||
is_equal_eps(sy, 1.0, epsilon) &&
|
||||
is_equal_eps(tx, 0.0, epsilon) &&
|
||||
is_equal_eps(ty, 0.0, epsilon);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
bool trans_affine::is_valid(double epsilon) const
|
||||
{
|
||||
return fabs(sx) > epsilon && fabs(sy) > epsilon;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
bool trans_affine::is_equal(const trans_affine& m, double epsilon) const
|
||||
{
|
||||
return is_equal_eps(sx, m.sx, epsilon) &&
|
||||
is_equal_eps(shy, m.shy, epsilon) &&
|
||||
is_equal_eps(shx, m.shx, epsilon) &&
|
||||
is_equal_eps(sy, m.sy, epsilon) &&
|
||||
is_equal_eps(tx, m.tx, epsilon) &&
|
||||
is_equal_eps(ty, m.ty, epsilon);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
double trans_affine::rotation() const
|
||||
{
|
||||
double x1 = 0.0;
|
||||
double y1 = 0.0;
|
||||
double x2 = 1.0;
|
||||
double y2 = 0.0;
|
||||
transform(&x1, &y1);
|
||||
transform(&x2, &y2);
|
||||
return atan2(y2-y1, x2-x1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void trans_affine::translation(double* dx, double* dy) const
|
||||
{
|
||||
*dx = tx;
|
||||
*dy = ty;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void trans_affine::scaling(double* x, double* y) const
|
||||
{
|
||||
double x1 = 0.0;
|
||||
double y1 = 0.0;
|
||||
double x2 = 1.0;
|
||||
double y2 = 1.0;
|
||||
trans_affine t(*this);
|
||||
t *= trans_affine_rotation(-rotation());
|
||||
t.transform(&x1, &y1);
|
||||
t.transform(&x2, &y2);
|
||||
*x = x2 - x1;
|
||||
*y = y2 - y1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
515
AVSEBOOKWriter/Common/agg_trans_affine.h
Normal file
515
AVSEBOOKWriter/Common/agg_trans_affine.h
Normal file
@ -0,0 +1,515 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef _USE_MATH_DEFINES
|
||||
#define _USE_MATH_DEFINES
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
namespace agg
|
||||
{
|
||||
const double affine_epsilon = 1e-14;
|
||||
|
||||
//------------------------------------------------------------is_equal_eps
|
||||
template<class T> inline bool is_equal_eps(T v1, T v2, T epsilon)
|
||||
{
|
||||
return fabs(v1 - v2) <= double(epsilon);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------deg2rad
|
||||
inline double deg2rad(double deg)
|
||||
{
|
||||
return deg * M_PI / 180.0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------rad2deg
|
||||
inline double rad2deg(double rad)
|
||||
{
|
||||
return rad * 180.0 / M_PI;
|
||||
}
|
||||
|
||||
//============================================================trans_affine
|
||||
//
|
||||
// See Implementation agg_trans_affine.cpp
|
||||
//
|
||||
// Affine transformation are linear transformations in Cartesian coordinates
|
||||
// (strictly speaking not only in Cartesian, but for the beginning we will
|
||||
// think so). They are rotation, scaling, translation and skewing.
|
||||
// After any affine transformation a line segment remains a line segment
|
||||
// and it will never become a curve.
|
||||
//
|
||||
// There will be no math about matrix calculations, since it has been
|
||||
// described many times. Ask yourself a very simple question:
|
||||
// "why do we need to understand and use some matrix stuff instead of just
|
||||
// rotating, scaling and so on". The answers are:
|
||||
//
|
||||
// 1. Any combination of transformations can be done by only 4 multiplications
|
||||
// and 4 additions in floating point.
|
||||
// 2. One matrix transformation is equivalent to the number of consecutive
|
||||
// discrete transformations, i.e. the matrix "accumulates" all transformations
|
||||
// in the order of their settings. Suppose we have 4 transformations:
|
||||
// * rotate by 30 degrees,
|
||||
// * scale X to 2.0,
|
||||
// * scale Y to 1.5,
|
||||
// * move to (100, 100).
|
||||
// The result will depend on the order of these transformations,
|
||||
// and the advantage of matrix is that the sequence of discret calls:
|
||||
// rotate(30), scaleX(2.0), scaleY(1.5), move(100,100)
|
||||
// will have exactly the same result as the following matrix transformations:
|
||||
//
|
||||
// affine_matrix m;
|
||||
// m *= rotate_matrix(30);
|
||||
// m *= scaleX_matrix(2.0);
|
||||
// m *= scaleY_matrix(1.5);
|
||||
// m *= move_matrix(100,100);
|
||||
//
|
||||
// m.transform_my_point_at_last(x, y);
|
||||
//
|
||||
// What is the good of it? In real life we will set-up the matrix only once
|
||||
// and then transform many points, let alone the convenience to set any
|
||||
// combination of transformations.
|
||||
//
|
||||
// So, how to use it? Very easy - literally as it's shown above. Not quite,
|
||||
// let us write a correct example:
|
||||
//
|
||||
// agg::trans_affine m;
|
||||
// m *= agg::trans_affine_rotation(30.0 * 3.1415926 / 180.0);
|
||||
// m *= agg::trans_affine_scaling(2.0, 1.5);
|
||||
// m *= agg::trans_affine_translation(100.0, 100.0);
|
||||
// m.transform(&x, &y);
|
||||
//
|
||||
// The affine matrix is all you need to perform any linear transformation,
|
||||
// but all transformations have origin point (0,0). It means that we need to
|
||||
// use 2 translations if we want to rotate someting around (100,100):
|
||||
//
|
||||
// m *= agg::trans_affine_translation(-100.0, -100.0); // move to (0,0)
|
||||
// m *= agg::trans_affine_rotation(30.0 * 3.1415926 / 180.0); // rotate
|
||||
// m *= agg::trans_affine_translation(100.0, 100.0); // move back to (100,100)
|
||||
//----------------------------------------------------------------------
|
||||
struct trans_affine
|
||||
{
|
||||
double sx, shy, shx, sy, tx, ty;
|
||||
|
||||
//------------------------------------------ Construction
|
||||
// Identity matrix
|
||||
trans_affine() :
|
||||
sx(1.0), shy(0.0), shx(0.0), sy(1.0), tx(0.0), ty(0.0)
|
||||
{}
|
||||
|
||||
// Custom matrix. Usually used in derived classes
|
||||
trans_affine(double v0, double v1, double v2,
|
||||
double v3, double v4, double v5) :
|
||||
sx(v0), shy(v1), shx(v2), sy(v3), tx(v4), ty(v5)
|
||||
{}
|
||||
|
||||
// Custom matrix from m[6]
|
||||
explicit trans_affine(const double* m) :
|
||||
sx(m[0]), shy(m[1]), shx(m[2]), sy(m[3]), tx(m[4]), ty(m[5])
|
||||
{}
|
||||
|
||||
// Rectangle to a parallelogram.
|
||||
trans_affine(double x1, double y1, double x2, double y2,
|
||||
const double* parl)
|
||||
{
|
||||
rect_to_parl(x1, y1, x2, y2, parl);
|
||||
}
|
||||
|
||||
// Parallelogram to a rectangle.
|
||||
trans_affine(const double* parl,
|
||||
double x1, double y1, double x2, double y2)
|
||||
{
|
||||
parl_to_rect(parl, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
// Arbitrary parallelogram transformation.
|
||||
trans_affine(const double* src, const double* dst)
|
||||
{
|
||||
parl_to_parl(src, dst);
|
||||
}
|
||||
|
||||
//---------------------------------- Parellelogram transformations
|
||||
// transform a parallelogram to another one. Src and dst are
|
||||
// pointers to arrays of three points (double[6], x1,y1,...) that
|
||||
// identify three corners of the parallelograms assuming implicit
|
||||
// fourth point. The arguments are arrays of double[6] mapped
|
||||
// to x1,y1, x2,y2, x3,y3 where the coordinates are:
|
||||
// *-----------------*
|
||||
// / (x3,y3)/
|
||||
// / /
|
||||
// /(x1,y1) (x2,y2)/
|
||||
// *-----------------*
|
||||
const trans_affine& parl_to_parl(const double* src,
|
||||
const double* dst);
|
||||
|
||||
const trans_affine& rect_to_parl(double x1, double y1,
|
||||
double x2, double y2,
|
||||
const double* parl);
|
||||
|
||||
const trans_affine& parl_to_rect(const double* parl,
|
||||
double x1, double y1,
|
||||
double x2, double y2);
|
||||
|
||||
|
||||
//------------------------------------------ Operations
|
||||
// Reset - load an identity matrix
|
||||
const trans_affine& reset();
|
||||
|
||||
// Direct transformations operations
|
||||
const trans_affine& translate(double x, double y);
|
||||
const trans_affine& rotate(double a);
|
||||
const trans_affine& scale(double s);
|
||||
const trans_affine& scale(double x, double y);
|
||||
|
||||
// Multiply matrix to another one
|
||||
const trans_affine& multiply(const trans_affine& m);
|
||||
|
||||
// Multiply "m" to "this" and assign the result to "this"
|
||||
const trans_affine& premultiply(const trans_affine& m);
|
||||
|
||||
// Multiply matrix to inverse of another one
|
||||
const trans_affine& multiply_inv(const trans_affine& m);
|
||||
|
||||
// Multiply inverse of "m" to "this" and assign the result to "this"
|
||||
const trans_affine& premultiply_inv(const trans_affine& m);
|
||||
|
||||
// Invert matrix. Do not try to invert degenerate matrices,
|
||||
// there's no check for validity. If you set scale to 0 and
|
||||
// then try to invert matrix, expect unpredictable result.
|
||||
const trans_affine& invert();
|
||||
|
||||
// Mirroring around X
|
||||
const trans_affine& flip_x();
|
||||
|
||||
// Mirroring around Y
|
||||
const trans_affine& flip_y();
|
||||
|
||||
//------------------------------------------- Load/Store
|
||||
// Store matrix to an array [6] of double
|
||||
void store_to(double* m) const
|
||||
{
|
||||
*m++ = sx; *m++ = shy; *m++ = shx; *m++ = sy; *m++ = tx; *m++ = ty;
|
||||
}
|
||||
|
||||
// Load matrix from an array [6] of double
|
||||
const trans_affine& load_from(const double* m)
|
||||
{
|
||||
sx = *m++; shy = *m++; shx = *m++; sy = *m++; tx = *m++; ty = *m++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------- Operators
|
||||
|
||||
// Multiply the matrix by another one
|
||||
const trans_affine& operator *= (const trans_affine& m)
|
||||
{
|
||||
return multiply(m);
|
||||
}
|
||||
|
||||
// Multiply the matrix by inverse of another one
|
||||
const trans_affine& operator /= (const trans_affine& m)
|
||||
{
|
||||
return multiply_inv(m);
|
||||
}
|
||||
|
||||
// Multiply the matrix by another one and return
|
||||
// the result in a separete matrix.
|
||||
trans_affine operator * (const trans_affine& m)
|
||||
{
|
||||
return trans_affine(*this).multiply(m);
|
||||
}
|
||||
|
||||
// Multiply the matrix by inverse of another one
|
||||
// and return the result in a separete matrix.
|
||||
trans_affine operator / (const trans_affine& m)
|
||||
{
|
||||
return trans_affine(*this).multiply_inv(m);
|
||||
}
|
||||
|
||||
// Calculate and return the inverse matrix
|
||||
trans_affine operator ~ () const
|
||||
{
|
||||
trans_affine ret = *this;
|
||||
return ret.invert();
|
||||
}
|
||||
|
||||
// Equal operator with default epsilon
|
||||
bool operator == (const trans_affine& m) const
|
||||
{
|
||||
return is_equal(m, affine_epsilon);
|
||||
}
|
||||
|
||||
// Not Equal operator with default epsilon
|
||||
bool operator != (const trans_affine& m) const
|
||||
{
|
||||
return !is_equal(m, affine_epsilon);
|
||||
}
|
||||
|
||||
//-------------------------------------------- Transformations
|
||||
// Direct transformation of x and y
|
||||
void transform(double* x, double* y) const;
|
||||
|
||||
// Direct transformation of x and y, 2x2 matrix only, no translation
|
||||
void transform_2x2(double* x, double* y) const;
|
||||
|
||||
// Inverse transformation of x and y. It works slower than the
|
||||
// direct transformation. For massive operations it's better to
|
||||
// invert() the matrix and then use direct transformations.
|
||||
void inverse_transform(double* x, double* y) const;
|
||||
|
||||
//-------------------------------------------- Auxiliary
|
||||
// Calculate the determinant of matrix
|
||||
double determinant() const
|
||||
{
|
||||
return sx * sy - shy * shx;
|
||||
}
|
||||
|
||||
// Calculate the reciprocal of the determinant
|
||||
double determinant_reciprocal() const
|
||||
{
|
||||
return 1.0 / (sx * sy - shy * shx);
|
||||
}
|
||||
|
||||
// Get the average scale (by X and Y).
|
||||
// Basically used to calculate the approximation_scale when
|
||||
// decomposinting curves into line segments.
|
||||
double scale() const;
|
||||
|
||||
// Check to see if the matrix is not degenerate
|
||||
bool is_valid(double epsilon = affine_epsilon) const;
|
||||
|
||||
// Check to see if it's an identity matrix
|
||||
bool is_identity(double epsilon = affine_epsilon) const;
|
||||
|
||||
// Check to see if two matrices are equal
|
||||
bool is_equal(const trans_affine& m, double epsilon = affine_epsilon) const;
|
||||
|
||||
// Determine the major parameters. Use with caution considering
|
||||
// possible degenerate cases.
|
||||
double rotation() const;
|
||||
void translation(double* dx, double* dy) const;
|
||||
void scaling(double* x, double* y) const;
|
||||
void scaling_abs(double* x, double* y) const;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline void trans_affine::transform(double* x, double* y) const
|
||||
{
|
||||
register double tmp = *x;
|
||||
*x = tmp * sx + *y * shx + tx;
|
||||
*y = tmp * shy + *y * sy + ty;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline void trans_affine::transform_2x2(double* x, double* y) const
|
||||
{
|
||||
register double tmp = *x;
|
||||
*x = tmp * sx + *y * shx;
|
||||
*y = tmp * shy + *y * sy;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline void trans_affine::inverse_transform(double* x, double* y) const
|
||||
{
|
||||
register double d = determinant_reciprocal();
|
||||
register double a = (*x - tx) * d;
|
||||
register double b = (*y - ty) * d;
|
||||
*x = a * sy - b * shx;
|
||||
*y = b * sx - a * shy;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline double trans_affine::scale() const
|
||||
{
|
||||
double x = 0.707106781 * sx + 0.707106781 * shx;
|
||||
double y = 0.707106781 * shy + 0.707106781 * sy;
|
||||
return sqrt(x*x + y*y);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::translate(double x, double y)
|
||||
{
|
||||
tx += x;
|
||||
ty += y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::rotate(double a)
|
||||
{
|
||||
double ca = cos(a);
|
||||
double sa = sin(a);
|
||||
double t0 = sx * ca - shy * sa;
|
||||
double t2 = shx * ca - sy * sa;
|
||||
double t4 = tx * ca - ty * sa;
|
||||
shy = sx * sa + shy * ca;
|
||||
sy = shx * sa + sy * ca;
|
||||
ty = tx * sa + ty * ca;
|
||||
sx = t0;
|
||||
shx = t2;
|
||||
tx = t4;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::scale(double x, double y)
|
||||
{
|
||||
double mm0 = x; // Possible hint for the optimizer
|
||||
double mm3 = y;
|
||||
sx *= mm0;
|
||||
shx *= mm0;
|
||||
tx *= mm0;
|
||||
shy *= mm3;
|
||||
sy *= mm3;
|
||||
ty *= mm3;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::scale(double s)
|
||||
{
|
||||
double m = s; // Possible hint for the optimizer
|
||||
sx *= m;
|
||||
shx *= m;
|
||||
tx *= m;
|
||||
shy *= m;
|
||||
sy *= m;
|
||||
ty *= m;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::premultiply(const trans_affine& m)
|
||||
{
|
||||
trans_affine t = m;
|
||||
return *this = t.multiply(*this);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::multiply_inv(const trans_affine& m)
|
||||
{
|
||||
trans_affine t = m;
|
||||
t.invert();
|
||||
return multiply(t);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::premultiply_inv(const trans_affine& m)
|
||||
{
|
||||
trans_affine t = m;
|
||||
t.invert();
|
||||
return *this = t.multiply(*this);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline void trans_affine::scaling_abs(double* x, double* y) const
|
||||
{
|
||||
// Used to calculate scaling coefficients in image resampling.
|
||||
// When there is considerable shear this method gives us much
|
||||
// better estimation than just sx, sy.
|
||||
*x = sqrt(sx * sx + shx * shx);
|
||||
*y = sqrt(shy * shy + sy * sy);
|
||||
}
|
||||
|
||||
//====================================================trans_affine_rotation
|
||||
// Rotation matrix. sin() and cos() are calculated twice for the same angle.
|
||||
// There's no harm because the performance of sin()/cos() is very good on all
|
||||
// modern processors. Besides, this operation is not going to be invoked too
|
||||
// often.
|
||||
class trans_affine_rotation : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_rotation(double a) :
|
||||
trans_affine(cos(a), sin(a), -sin(a), cos(a), 0.0, 0.0)
|
||||
{}
|
||||
};
|
||||
|
||||
//====================================================trans_affine_scaling
|
||||
// Scaling matrix. x, y - scale coefficients by X and Y respectively
|
||||
class trans_affine_scaling : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_scaling(double x, double y) :
|
||||
trans_affine(x, 0.0, 0.0, y, 0.0, 0.0)
|
||||
{}
|
||||
|
||||
trans_affine_scaling(double s) :
|
||||
trans_affine(s, 0.0, 0.0, s, 0.0, 0.0)
|
||||
{}
|
||||
};
|
||||
|
||||
//================================================trans_affine_translation
|
||||
// Translation matrix
|
||||
class trans_affine_translation : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_translation(double x, double y) :
|
||||
trans_affine(1.0, 0.0, 0.0, 1.0, x, y)
|
||||
{}
|
||||
};
|
||||
|
||||
//====================================================trans_affine_skewing
|
||||
// Sckewing (shear) matrix
|
||||
class trans_affine_skewing : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_skewing(double x, double y) :
|
||||
trans_affine(1.0, tan(y), tan(x), 1.0, 0.0, 0.0)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
//===============================================trans_affine_line_segment
|
||||
// Rotate, Scale and Translate, associating 0...dist with line segment
|
||||
// x1,y1,x2,y2
|
||||
class trans_affine_line_segment : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_line_segment(double x1, double y1, double x2, double y2,
|
||||
double dist)
|
||||
{
|
||||
double dx = x2 - x1;
|
||||
double dy = y2 - y1;
|
||||
if(dist > 0.0)
|
||||
{
|
||||
multiply(trans_affine_scaling(sqrt(dx * dx + dy * dy) / dist));
|
||||
}
|
||||
multiply(trans_affine_rotation(atan2(dy, dx)));
|
||||
multiply(trans_affine_translation(x1, y1));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//============================================trans_affine_reflection_unit
|
||||
// Reflection matrix. Reflect coordinates across the line through
|
||||
// the origin containing the unit vector (ux, uy).
|
||||
// Contributed by John Horigan
|
||||
class trans_affine_reflection_unit : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_reflection_unit(double ux, double uy) :
|
||||
trans_affine(2.0 * ux * ux - 1.0,
|
||||
2.0 * ux * uy,
|
||||
2.0 * ux * uy,
|
||||
2.0 * uy * uy - 1.0,
|
||||
0.0, 0.0)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
//=================================================trans_affine_reflection
|
||||
// Reflection matrix. Reflect coordinates across the line through
|
||||
// the origin at the angle a or containing the non-unit vector (x, y).
|
||||
// Contributed by John Horigan
|
||||
class trans_affine_reflection : public trans_affine_reflection_unit
|
||||
{
|
||||
public:
|
||||
trans_affine_reflection(double a) :
|
||||
trans_affine_reflection_unit(cos(a), sin(a))
|
||||
{}
|
||||
|
||||
|
||||
trans_affine_reflection(double x, double y) :
|
||||
trans_affine_reflection_unit(x / sqrt(x * x + y * y), y / sqrt(x * x + y * y))
|
||||
{}
|
||||
};
|
||||
}
|
||||
286
AVSEBOOKWriter/Common/ap_AggPlusEnums.h
Normal file
286
AVSEBOOKWriter/Common/ap_AggPlusEnums.h
Normal file
@ -0,0 +1,286 @@
|
||||
//
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _AGGPLUSENUMS_H
|
||||
#define _AGGPLUSENUMS_H
|
||||
|
||||
#include "ap_AggPlusTypes.h"
|
||||
|
||||
//#define __cplusplus
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
|
||||
#define PixelFormatIndexed 0x00010000 // Indexes into a palette
|
||||
#define PixelFormatGDI 0x00020000 // Is a GDI-supported format
|
||||
#define PixelFormatAlpha 0x00040000 // Has an alpha component
|
||||
#define PixelFormatPAlpha 0x00080000 // Pre-multiplied alpha
|
||||
#define PixelFormatExtended 0x00100000 // Extended color 16 bits/channel
|
||||
#define PixelFormatCanonical 0x00200000
|
||||
|
||||
#define PixelFormatUndefined 0
|
||||
#define PixelFormatDontCare 0
|
||||
|
||||
#define PixelFormat1bppIndexed (1 | ( 1 << 8) | PixelFormatIndexed | PixelFormatGDI)
|
||||
#define PixelFormat4bppIndexed (2 | ( 4 << 8) | PixelFormatIndexed | PixelFormatGDI)
|
||||
#define PixelFormat8bppIndexed (3 | ( 8 << 8) | PixelFormatIndexed | PixelFormatGDI)
|
||||
#define PixelFormat16bppGrayScale (4 | (16 << 8) | PixelFormatExtended)
|
||||
#define PixelFormat16bppRGB555 (5 | (16 << 8) | PixelFormatGDI)
|
||||
#define PixelFormat16bppRGB565 (6 | (16 << 8) | PixelFormatGDI)
|
||||
#define PixelFormat16bppARGB1555 (7 | (16 << 8) | PixelFormatAlpha | PixelFormatGDI)
|
||||
#define PixelFormat24bppRGB (8 | (24 << 8) | PixelFormatGDI)
|
||||
#define PixelFormat32bppRGB (9 | (32 << 8) | PixelFormatGDI)
|
||||
#define PixelFormat32bppARGB (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical)
|
||||
#define PixelFormat32bppPARGB (11 | (32 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatGDI)
|
||||
#define PixelFormat48bppRGB (12 | (48 << 8) | PixelFormatExtended)
|
||||
#define PixelFormat64bppARGB (13 | (64 << 8) | PixelFormatAlpha | PixelFormatCanonical | PixelFormatExtended)
|
||||
#define PixelFormat64bppPARGB (14 | (64 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatExtended)
|
||||
#define PixelFormatMax 15
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Matrix Order
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum MatrixOrder
|
||||
{
|
||||
MatrixOrderPrepend = 0,
|
||||
MatrixOrderAppend = 1
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Dash style constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum DashStyle
|
||||
{
|
||||
DashStyleSolid, // 0
|
||||
DashStyleDash, // 1
|
||||
DashStyleDot, // 2
|
||||
DashStyleDashDot, // 3
|
||||
DashStyleDashDotDot, // 4
|
||||
DashStyleCustom // 5
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Line join constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum LineJoin
|
||||
{
|
||||
LineJoinMiter = 0,
|
||||
LineJoinBevel = 1,
|
||||
LineJoinRound = 2,
|
||||
LineJoinMiterClipped = 3
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Line cap constants
|
||||
//--------------------------------------------------------------------------
|
||||
enum LineCap
|
||||
{
|
||||
LineCapFlat = 0,
|
||||
LineCapSquare = 1,
|
||||
LineCapRound = 2,
|
||||
LineCapTriangle = 3,
|
||||
|
||||
LineCapNoAnchor = 0x10, // corresponds to flat cap
|
||||
LineCapSquareAnchor = 0x11, // corresponds to square cap
|
||||
LineCapRoundAnchor = 0x12, // corresponds to round cap
|
||||
LineCapDiamondAnchor = 0x13, // corresponds to triangle cap
|
||||
LineCapArrowAnchor = 0x14, // no correspondence
|
||||
|
||||
LineCapCustom = 0xff, // custom cap
|
||||
|
||||
LineCapAnchorMask = 0xf0 // mask to check for anchor or not.
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Brush types
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum BrushType
|
||||
{
|
||||
BrushTypeSolidColor = 0,
|
||||
BrushTypeHatchFill = 1,
|
||||
BrushTypeTextureFill = 2,
|
||||
BrushTypePathGradient = 3,
|
||||
BrushTypeLinearGradient = 4
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Various wrap modes for brushes
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum WrapMode
|
||||
{
|
||||
WrapModeTile, // 0
|
||||
WrapModeTileFlipX, // 1
|
||||
WrapModeTileFlipY, // 2
|
||||
WrapModeTileFlipXY, // 3
|
||||
WrapModeClamp // 4
|
||||
};
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// FontStyle: face types and common styles
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum FontStyle
|
||||
{
|
||||
FontStyleRegular = 0,
|
||||
FontStyleBold = 1,
|
||||
FontStyleItalic = 2,
|
||||
FontStyleBoldItalic = 3,
|
||||
FontStyleUnderline = 4,
|
||||
FontStyleStrikeout = 8
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// String alignment flags
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
enum StringAlignment
|
||||
{
|
||||
// Left edge for left-to-right text,
|
||||
// right for right-to-left text,
|
||||
// and top for vertical
|
||||
StringAlignmentNear = 0,
|
||||
StringAlignmentCenter = 1,
|
||||
StringAlignmentFar = 2
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//############## Not implemented-Used
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Unit constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum Unit
|
||||
{
|
||||
UnitWorld, // 0 -- World coordinate (non-physical unit)
|
||||
UnitDisplay, // 1 -- Variable -- for PageTransform only
|
||||
UnitPixel, // 2 -- Each unit is one device pixel.
|
||||
UnitPoint, // 3 -- Each unit is a printer's point, or 1/72 inch.
|
||||
UnitInch, // 4 -- Each unit is 1 inch.
|
||||
UnitDocument, // 5 -- Each unit is 1/300 inch.
|
||||
UnitMillimeter // 6 -- Each unit is 1 millimeter.
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Text Rendering Hint
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
enum TextRenderingHint
|
||||
{
|
||||
TextRenderingHintSystemDefault = 0, // Glyph with system default rendering hint
|
||||
TextRenderingHintSingleBitPerPixelGridFit, // Glyph bitmap with hinting
|
||||
TextRenderingHintSingleBitPerPixel, // Glyph bitmap without hinting
|
||||
TextRenderingHintAntiAliasGridFit, // Glyph anti-alias bitmap with hinting
|
||||
TextRenderingHintAntiAlias, // Glyph anti-alias bitmap without hinting
|
||||
TextRenderingHintClearTypeGridFit // Glyph CT bitmap with hinting
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Quality mode constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum QualityMode
|
||||
{
|
||||
QualityModeInvalid = -1,
|
||||
QualityModeDefault = 0,
|
||||
QualityModeLow = 1, // Best performance
|
||||
QualityModeHigh = 2 // Best rendering quality
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Alpha Compositing mode constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum CompositingMode
|
||||
{
|
||||
CompositingModeSourceOver, // 0
|
||||
CompositingModeSourceCopy // 1
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Alpha Compositing quality constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum CompositingQuality
|
||||
{
|
||||
CompositingQualityInvalid = QualityModeInvalid,
|
||||
CompositingQualityDefault = QualityModeDefault,
|
||||
CompositingQualityHighSpeed = QualityModeLow,
|
||||
CompositingQualityHighQuality = QualityModeHigh,
|
||||
CompositingQualityGammaCorrected,
|
||||
CompositingQualityAssumeLinear
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Smoothing Mode
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
enum SmoothingMode
|
||||
{
|
||||
SmoothingModeInvalid = QualityModeInvalid,
|
||||
SmoothingModeDefault = QualityModeDefault,
|
||||
SmoothingModeHighSpeed = QualityModeLow,
|
||||
SmoothingModeHighQuality = QualityModeHigh,
|
||||
SmoothingModeNone,
|
||||
SmoothingModeAntiAlias
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Interpolation modes
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum InterpolationMode
|
||||
{
|
||||
InterpolationModeInvalid = QualityModeInvalid,
|
||||
InterpolationModeDefault = QualityModeDefault,
|
||||
InterpolationModeLowQuality = QualityModeLow,
|
||||
InterpolationModeHighQuality = QualityModeHigh,
|
||||
InterpolationModeBilinear,
|
||||
InterpolationModeBicubic,
|
||||
InterpolationModeNearestNeighbor,
|
||||
InterpolationModeHighQualityBilinear,
|
||||
InterpolationModeHighQualityBicubic
|
||||
};
|
||||
|
||||
|
||||
|
||||
enum StringFormatFlags
|
||||
{
|
||||
//not supp StringFormatFlagsDirectionRightToLeft = 0x00000001,
|
||||
//not supp StringFormatFlagsDirectionVertical = 0x00000002,
|
||||
//not supp StringFormatFlagsNoFitBlackBox = 0x00000004,
|
||||
//not supp StringFormatFlagsDisplayFormatControl = 0x00000020,
|
||||
//not supp StringFormatFlagsNoFontFallback = 0x00000400,
|
||||
//not supp StringFormatFlagsMeasureTrailingSpaces = 0x00000800,
|
||||
//not supp StringFormatFlagsNoWrap = 0x00001000,
|
||||
StringFormatFlagsLineLimit = 0x00002000
|
||||
|
||||
//not supp StringFormatFlagsNoClip = 0x00004000
|
||||
};
|
||||
|
||||
|
||||
} //namespace Aggplus
|
||||
|
||||
#endif // !defined(_AGGPLUSENUMS_H)
|
||||
173
AVSEBOOKWriter/Common/ap_AggPlusTypes.h
Normal file
173
AVSEBOOKWriter/Common/ap_AggPlusTypes.h
Normal file
@ -0,0 +1,173 @@
|
||||
|
||||
|
||||
#ifndef _AGGPLUSTYPES_H
|
||||
#define _AGGPLUSTYPES_H
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
|
||||
typedef float REAL;
|
||||
typedef int INT;
|
||||
typedef unsigned int *PUINT;
|
||||
typedef unsigned long ARGB;
|
||||
|
||||
typedef INT PixelFormat;
|
||||
|
||||
#define REAL_MAX FLT_MAX
|
||||
#define REAL_MIN FLT_MIN
|
||||
#define REAL_TOLERANCE (FLT_MIN * 100)
|
||||
#define REAL_EPSILON 1.192092896e-07F /* FLT_EPSILON */
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Status return values from AGG+ methods
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum Status
|
||||
{
|
||||
Ok = 0,
|
||||
GenericError = 1,
|
||||
InvalidParameter = 2,
|
||||
OutOfMemory = 3,
|
||||
ObjectBusy = 4,
|
||||
InsufficientBuffer = 5,
|
||||
NotImplemented = 6,
|
||||
Win32Error = 7,
|
||||
WrongState = 8,
|
||||
Aborted = 9,
|
||||
FileNotFound = 10,
|
||||
ValueOverflow = 11,
|
||||
AccessDenied = 12,
|
||||
UnknownImageFormat = 13,
|
||||
FontFamilyNotFound = 14,
|
||||
FontStyleNotFound = 15,
|
||||
NotTrueTypeFont = 16,
|
||||
UnsupportedGdiplusVersion = 17,
|
||||
AggplusNotInitialized = 18,
|
||||
PropertyNotFound = 19,
|
||||
PropertyNotSupported = 20
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class SizeF
|
||||
{
|
||||
public:
|
||||
SizeF() : Width(0.0f), Height(0.0f) { }
|
||||
SizeF(const SizeF& size) : Width(size.Width), Height(size.Height) { }
|
||||
SizeF(REAL width, REAL height) : Width(width), Height(height) { }
|
||||
|
||||
SizeF operator+(const SizeF& sz) const { return SizeF(Width+sz.Width, Height+sz.Height); }
|
||||
SizeF operator-(const SizeF& sz) const { return SizeF(Width-sz.Width, Height-sz.Height); }
|
||||
BOOL Equals(const SizeF& sz) const { return((Width == sz.Width) && (Height == sz.Height)); }
|
||||
BOOL Empty() const { return(Width == 0.0f && Height == 0.0f); }
|
||||
|
||||
public:
|
||||
REAL Width, Height;
|
||||
};
|
||||
|
||||
|
||||
class PointF
|
||||
{
|
||||
public:
|
||||
PointF() : X(0.0f), Y(0.0f) { }
|
||||
PointF(const PointF &point) : X(point.X), Y(point.Y) { }
|
||||
PointF(const SizeF &size) : X(size.Width), Y(size.Height) { }
|
||||
PointF(REAL x, REAL y) : X(x), Y(y) { }
|
||||
//~PointF() { }
|
||||
BOOL Equals(const PointF& point) const { return(X==point.X && Y==point.Y); }
|
||||
PointF operator+(const PointF& point) const { return PointF(X + point.X, Y + point.Y); }
|
||||
PointF operator-(const PointF& point) const { return PointF(X - point.X, Y - point.Y); }
|
||||
public:
|
||||
REAL X, Y;
|
||||
};
|
||||
|
||||
class RectF
|
||||
{
|
||||
public:
|
||||
RectF() : X(0.0f), Y(0.0f), Width(0.0f), Height(0.0f) { }
|
||||
RectF(REAL x, REAL y, REAL width, REAL height) : X(x), Y(y), Width(width), Height(height) { }
|
||||
RectF(RECT rct)
|
||||
{ X = REAL(rct.left); Y = REAL(rct.top); Width = REAL(rct.right-rct.left); Height=REAL(rct.bottom-rct.top);}
|
||||
RectF(const PointF& location, const SizeF& size) : X(location.X), Y(location.Y), Width(size.Width), Height(size.Height) { }
|
||||
|
||||
RectF* Clone() const { return new RectF(X, Y, Width, Height); }
|
||||
|
||||
void GetLocation(PointF* point) const { point->X = X; point->Y = Y; }
|
||||
void GetSize(SizeF* size) const { size->Width = Width; size->Height = Height; }
|
||||
void GetBounds(RectF* rect) const { rect->X = X; rect->Y = Y; rect->Width = Width; rect->Height = Height; }
|
||||
REAL GetLeft() const { return X; }
|
||||
REAL GetTop() const { return Y; }
|
||||
REAL GetRight() const { return X+Width; }
|
||||
REAL GetBottom() const { return Y+Height; }
|
||||
BOOL IsEmptyArea() const { return (Width <= REAL_EPSILON) || (Height <= REAL_EPSILON); }
|
||||
BOOL Equals(const RectF & rect) const
|
||||
{
|
||||
return X == rect.X && Y == rect.Y &&
|
||||
Width == rect.Width && Height == rect.Height;
|
||||
}
|
||||
BOOL Contains(REAL x, REAL y) const
|
||||
{
|
||||
return x >= X && x < X+Width &&
|
||||
y >= Y && y < Y+Height;
|
||||
}
|
||||
BOOL Contains(const PointF& pt) const { return Contains(pt.X, pt.Y); }
|
||||
BOOL Contains(const RectF& rect) const
|
||||
{
|
||||
return (X <= rect.X) && (rect.GetRight() <= GetRight()) &&
|
||||
(Y <= rect.Y) && (rect.GetBottom() <= GetBottom());
|
||||
}
|
||||
|
||||
void Inflate(REAL dx, REAL dy) { X -= dx; Y -= dy; Width += 2*dx; Height += 2*dy; }
|
||||
void Inflate(const PointF& point) { Inflate(point.X, point.Y); }
|
||||
|
||||
BOOL Intersect(const RectF& rect) { return Intersect(*this, *this, rect); }
|
||||
static BOOL Intersect(RectF& c, const RectF& a, const RectF& b)
|
||||
{
|
||||
REAL right = min(a.GetRight(), b.GetRight());
|
||||
REAL bottom = min(a.GetBottom(), b.GetBottom());
|
||||
REAL left = max(a.GetLeft(), b.GetLeft());
|
||||
REAL top = max(a.GetTop(), b.GetTop());
|
||||
|
||||
c.X = left;
|
||||
c.Y = top;
|
||||
c.Width = right - left;
|
||||
c.Height = bottom - top;
|
||||
return !c.IsEmptyArea();
|
||||
}
|
||||
|
||||
BOOL IntersectsWith(const RectF& rect) const
|
||||
{
|
||||
return (GetLeft() < rect.GetRight() &&
|
||||
GetTop() < rect.GetBottom() &&
|
||||
GetRight() > rect.GetLeft() &&
|
||||
GetBottom() > rect.GetTop());
|
||||
}
|
||||
|
||||
static BOOL Union(RectF& c, const RectF& a, const RectF& b)
|
||||
{
|
||||
REAL right = max(a.GetRight(), b.GetRight());
|
||||
REAL bottom = max(a.GetBottom(), b.GetBottom());
|
||||
REAL left = min(a.GetLeft(), b.GetLeft());
|
||||
REAL top = min(a.GetTop(), b.GetTop());
|
||||
|
||||
c.X = left;
|
||||
c.Y = top;
|
||||
c.Width = right - left;
|
||||
c.Height = bottom - top;
|
||||
return !c.IsEmptyArea();
|
||||
}
|
||||
|
||||
void Offset(const PointF& point) { Offset(point.X, point.Y); }
|
||||
void Offset(REAL dx, REAL dy) { X += dx; Y += dy; }
|
||||
|
||||
public:
|
||||
REAL X, Y, Width, Height;
|
||||
};
|
||||
|
||||
|
||||
} //namespace Aggplus
|
||||
|
||||
#endif // _AGGPLUSTYPES_H
|
||||
1624
AVSEBOOKWriter/Common/fontmanagerbase.h
Normal file
1624
AVSEBOOKWriter/Common/fontmanagerbase.h
Normal file
File diff suppressed because it is too large
Load Diff
1437
AVSEBOOKWriter/Common/structures.h
Normal file
1437
AVSEBOOKWriter/Common/structures.h
Normal file
File diff suppressed because it is too large
Load Diff
1397
AVSEBOOKWriter/EBOOKWriter.cpp
Normal file
1397
AVSEBOOKWriter/EBOOKWriter.cpp
Normal file
File diff suppressed because it is too large
Load Diff
596
AVSEBOOKWriter/EBOOKWriter.h
Normal file
596
AVSEBOOKWriter/EBOOKWriter.h
Normal file
@ -0,0 +1,596 @@
|
||||
// EBOOKWriter.h : Declaration of the CAVSEBOOKWriter
|
||||
|
||||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "resource.h" // main symbols
|
||||
|
||||
#include "MOBIFormat/MobiReader.h"
|
||||
#include "Writers/Writer_Fb2.h"
|
||||
#include "Writers/Writer_Epub.h"
|
||||
#include "Writers/Writer_Mobi.h"
|
||||
#include "Writers/Writer_Docx.h"
|
||||
|
||||
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
|
||||
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
|
||||
#endif
|
||||
|
||||
// IAVSEBOOKWriter
|
||||
[object, uuid("304A27A4-1792-4a1b-BD44-CE5F127D2895"), dual, pointer_default(unique)]
|
||||
__interface IAVSEBOOKWriter : IAVSRenderer
|
||||
{
|
||||
[id(11001)] HRESULT Initialize([in]BSTR bsXMLOptions);
|
||||
[id(11002)] HRESULT SetMetadata([in]BSTR bsXMLOptions);
|
||||
|
||||
[id(12001)] HRESULT CreateOfficeFile([in]BSTR bstrFileName, [in] LONG lFileType);
|
||||
[id(12002)] HRESULT CloseFile();
|
||||
|
||||
[id(12003), propget] HRESULT TempDirectory([out, retval]BSTR* pbstrFileName);
|
||||
[id(12003), propput] HRESULT TempDirectory([in]BSTR bstrFileName);
|
||||
|
||||
[id(12004), propget] HRESULT SrcFileType([out, retval]LONG* plSrcFileType);
|
||||
[id(12004), propput] HRESULT SrcFileType([in]LONG lSrcType);
|
||||
|
||||
[id(12500), propget] HRESULT CommandRenderer([out, retval] IUnknown** ppunkRend);
|
||||
[id(12500), propput] HRESULT CommandRenderer([in] IUnknown* punkRend);
|
||||
};
|
||||
|
||||
// CAVSEBOOKWriter
|
||||
[coclass, default(IAVSEBOOKWriter), threading(apartment), vi_progid("AVSEBOOKWriter.EBOOKWriter"), progid("AVSEBOOKWriter.EBOOKWriter.1"), version(1.0), uuid("8B8FEDFC-38D5-4d13-BDE5-549CD09A6809")]
|
||||
class ATL_NO_VTABLE CAVSEBOOKWriter :
|
||||
public IAVSEBOOKWriter, public IAVSRenderer2
|
||||
{
|
||||
private:
|
||||
NSStructures::CPen m_oPen; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> AVSGraphics)
|
||||
NSStructures::CBrush m_oBrush;
|
||||
NSStructures::CFont m_oFont;
|
||||
NSStructures::CFormat m_oFormat;
|
||||
NSStructures::CShadow m_oShadow;
|
||||
NSStructures::CEdgeText m_oEdge;
|
||||
|
||||
AVSGraphics::IAVSGraphicSimpleComverter* m_pSimpleGraphicsConverter; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
AVSGraphics::IAVSFontManager* m_pFontManager; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
NSCommon::CMatrix m_oBaseTransform; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
NSCommon::CMatrix m_oTransform; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
NSCommon::CMatrix m_oFullTransform; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (m_oBaseTransform * m_oTransform)
|
||||
|
||||
double m_dTransformAngle;
|
||||
|
||||
LONG m_lCurrentCommandType; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
bool m_bIsMetafileDrawing;
|
||||
|
||||
double m_dDpiX;
|
||||
double m_dDpiY;
|
||||
|
||||
LONG m_lClipMode;
|
||||
NSStructures::CFont m_oInstalledFont;
|
||||
|
||||
double m_dWidth;
|
||||
double m_dHeight;
|
||||
bool m_bPageAdded;
|
||||
|
||||
NSEBook::CWriter m_oWriter;
|
||||
|
||||
CRITICAL_SECTION m_oCS;
|
||||
|
||||
CString m_strDstFilePath;
|
||||
CString m_strTempDirectory;
|
||||
|
||||
LONG m_lSrcType;
|
||||
LONG m_lDstType;
|
||||
|
||||
NSEBook::CRenderers* m_pRenderers;
|
||||
|
||||
DWORD m_lCommandFlags;
|
||||
|
||||
AVSGraphics::IAVSDocumentRenderer * m_piCommandsRenderer;
|
||||
|
||||
public:
|
||||
CAVSEBOOKWriter()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
|
||||
/*
|
||||
NSMobi::CMobiReader oReaderMobi;
|
||||
oReaderMobi.OpenFile(_T("C:\\PPTMemory\\Guide.mobi"));
|
||||
oReaderMobi.CloseFile();
|
||||
*/
|
||||
|
||||
/*
|
||||
m_oWriter.m_oFormat.LoadFromFile(_T("C:\\PPTMemory\\test_format_input.xml"));
|
||||
m_oWriter.m_oFormat.SaveToFile(_T("C:\\PPTMemory\\test_format_output.xml"));
|
||||
m_lDstType = 1;
|
||||
CloseFile();
|
||||
*/
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
DECLARE_PROTECT_FINAL_CONSTRUCT()
|
||||
|
||||
HRESULT FinalConstruct()
|
||||
{
|
||||
m_strDstFilePath = _T("");
|
||||
m_strTempDirectory = _T("");
|
||||
|
||||
InitializeCriticalSection(&m_oCS);
|
||||
|
||||
m_dDpiX = 96.0;
|
||||
m_dDpiY = 96.0;
|
||||
|
||||
m_lClipMode = c_nClipRegionTypeWinding;
|
||||
|
||||
m_lCommandFlags = 0;
|
||||
|
||||
m_pSimpleGraphicsConverter = NULL;
|
||||
CoCreateInstance(AVSGraphics::CLSID_CAVSGraphicSimpleComverter, NULL, CLSCTX_ALL, AVSGraphics::IID_IAVSGraphicSimpleComverter, (void**)&m_pSimpleGraphicsConverter);
|
||||
|
||||
IUnknown* punkRenderer = NULL;
|
||||
this->QueryInterface(IID_IUnknown, (void**)&punkRenderer);
|
||||
|
||||
m_pSimpleGraphicsConverter->put_Renderer(punkRenderer);
|
||||
RELEASEINTERFACE(punkRenderer);
|
||||
|
||||
m_dTransformAngle = 0.0;
|
||||
m_bIsMetafileDrawing = false;
|
||||
m_pFontManager = NULL;
|
||||
|
||||
m_pRenderers = NULL;
|
||||
m_piCommandsRenderer = NULL;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void FinalRelease()
|
||||
{
|
||||
CloseFile();
|
||||
|
||||
RELEASEINTERFACE(m_piCommandsRenderer);
|
||||
DeleteCriticalSection(&m_oCS);
|
||||
}
|
||||
|
||||
public:
|
||||
// IAVSRenderer Methods
|
||||
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-----------------------------------------------------------------------------
|
||||
STDMETHOD(get_Type)(LONG* lType);
|
||||
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --------------------------------------------------
|
||||
STDMETHOD(NewPage)();
|
||||
STDMETHOD(get_Height)(double* dHeight);
|
||||
STDMETHOD(put_Height)(double dHeight);
|
||||
STDMETHOD(get_Width)(double* dWidth);
|
||||
STDMETHOD(put_Width)(double dWidth);
|
||||
STDMETHOD(get_DpiX)(double* dDpiX);
|
||||
STDMETHOD(get_DpiY)(double* dDpiY);
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ----------------------------------------------
|
||||
STDMETHOD(SetPen)(BSTR bsXML);
|
||||
|
||||
STDMETHOD(get_PenColor)(LONG* lColor);
|
||||
STDMETHOD(put_PenColor)(LONG lColor);
|
||||
STDMETHOD(get_PenAlpha)(LONG* lAlpha);
|
||||
STDMETHOD(put_PenAlpha)(LONG lAlpha);
|
||||
STDMETHOD(get_PenSize)(double* dSize);
|
||||
STDMETHOD(put_PenSize)(double dSize);
|
||||
STDMETHOD(get_PenDashStyle)(BYTE* val);
|
||||
STDMETHOD(put_PenDashStyle)(BYTE val);
|
||||
STDMETHOD(get_PenLineStartCap)(BYTE* val);
|
||||
STDMETHOD(put_PenLineStartCap)(BYTE val);
|
||||
STDMETHOD(get_PenLineEndCap)(BYTE* val);
|
||||
STDMETHOD(put_PenLineEndCap)(BYTE val);
|
||||
STDMETHOD(get_PenLineJoin)(BYTE* val);
|
||||
STDMETHOD(put_PenLineJoin)(BYTE val);
|
||||
STDMETHOD(get_PenDashOffset)(double* val);
|
||||
STDMETHOD(put_PenDashOffset)(double val);
|
||||
STDMETHOD(get_PenAlign)(LONG* val);
|
||||
STDMETHOD(put_PenAlign)(LONG val);
|
||||
STDMETHOD(get_PenMiterLimit)(double* val);
|
||||
STDMETHOD(put_PenMiterLimit)(double val);
|
||||
STDMETHOD(PenDashPattern)(SAFEARRAY* pPattern);
|
||||
|
||||
STDMETHOD(SetBrush)(BSTR bsXML);
|
||||
|
||||
STDMETHOD(get_BrushType)(LONG* lType);
|
||||
STDMETHOD(put_BrushType)(LONG lType);
|
||||
STDMETHOD(get_BrushColor1)(LONG* lColor);
|
||||
STDMETHOD(put_BrushColor1)(LONG lColor);
|
||||
STDMETHOD(get_BrushAlpha1)(LONG* lAlpha);
|
||||
STDMETHOD(put_BrushAlpha1)(LONG lAlpha);
|
||||
STDMETHOD(get_BrushColor2)(LONG* lColor);
|
||||
STDMETHOD(put_BrushColor2)(LONG lColor);
|
||||
STDMETHOD(get_BrushAlpha2)(LONG* lAlpha);
|
||||
STDMETHOD(put_BrushAlpha2)(LONG lAlpha);
|
||||
STDMETHOD(get_BrushTexturePath)(BSTR* bsPath);
|
||||
STDMETHOD(put_BrushTexturePath)(BSTR bsPath);
|
||||
STDMETHOD(get_BrushTextureMode)(LONG* lMode);
|
||||
STDMETHOD(put_BrushTextureMode)(LONG lMode);
|
||||
STDMETHOD(get_BrushTextureAlpha)(LONG* lTxAlpha);
|
||||
STDMETHOD(put_BrushTextureAlpha)(LONG lTxAlpha);
|
||||
STDMETHOD(get_BrushLinearAngle)(double* dAngle);
|
||||
STDMETHOD(put_BrushLinearAngle)(double dAngle);
|
||||
STDMETHOD(BrushRect)(BOOL val, double left, double top, double width, double height);
|
||||
|
||||
STDMETHOD(SetFont)(BSTR bsXML);
|
||||
|
||||
STDMETHOD(get_FontName)(BSTR* bsName);
|
||||
STDMETHOD(put_FontName)(BSTR bsName);
|
||||
STDMETHOD(get_FontPath)(BSTR* bsName);
|
||||
STDMETHOD(put_FontPath)(BSTR bsName);
|
||||
STDMETHOD(get_FontSize)(double* dSize);
|
||||
STDMETHOD(put_FontSize)(double dSize);
|
||||
STDMETHOD(get_FontStyle)(LONG* lStyle);
|
||||
STDMETHOD(put_FontStyle)(LONG lStyle);
|
||||
STDMETHOD(get_FontStringGID)(BOOL* bGID);
|
||||
STDMETHOD(put_FontStringGID)(BOOL bGID);
|
||||
STDMETHOD(get_FontCharSpace)(double* dSpace);
|
||||
STDMETHOD(put_FontCharSpace)(double dSpace);
|
||||
|
||||
STDMETHOD(SetShadow)(BSTR bsXML);
|
||||
|
||||
STDMETHOD(get_ShadowDistanceX)(double* val);
|
||||
STDMETHOD(put_ShadowDistanceX)(double val);
|
||||
STDMETHOD(get_ShadowDistanceY)(double* val);
|
||||
STDMETHOD(put_ShadowDistanceY)(double val);
|
||||
STDMETHOD(get_ShadowBlurSize)(double* val);
|
||||
STDMETHOD(put_ShadowBlurSize)(double val);
|
||||
STDMETHOD(get_ShadowColor)(LONG* val);
|
||||
STDMETHOD(put_ShadowColor)(LONG val);
|
||||
STDMETHOD(get_ShadowAlpha)(LONG* val);
|
||||
STDMETHOD(put_ShadowAlpha)(LONG val);
|
||||
STDMETHOD(get_ShadowVisible)(BOOL* val);
|
||||
STDMETHOD(put_ShadowVisible)(BOOL val);
|
||||
|
||||
STDMETHOD(SetEdgeText)(BSTR bsXML);
|
||||
|
||||
STDMETHOD(get_EdgeVisible)(LONG* val);
|
||||
STDMETHOD(put_EdgeVisible)(LONG val);
|
||||
STDMETHOD(get_EdgeColor)(LONG* val);
|
||||
STDMETHOD(put_EdgeColor)(LONG val);
|
||||
STDMETHOD(get_EdgeAlpha)(LONG* val);
|
||||
STDMETHOD(put_EdgeAlpha)(LONG val);
|
||||
STDMETHOD(get_EdgeDist)(double* val);
|
||||
STDMETHOD(put_EdgeDist)(double val);
|
||||
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --------------------------------------------------------
|
||||
STDMETHOD(CommandDrawText)(BSTR bsText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset);
|
||||
STDMETHOD(CommandDrawTextEx)(BSTR bsUnicodeText, BSTR bsGidText, BSTR bsSourceCodeText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset, DWORD lFlags);
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ---------------------------------------------------------------
|
||||
STDMETHOD(BeginCommand)(DWORD lType);
|
||||
STDMETHOD(EndCommand)(DWORD lType);
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> Graphics Path -----------------------------------------------
|
||||
STDMETHOD(PathCommandMoveTo)(double fX, double fY);
|
||||
STDMETHOD(PathCommandLineTo)(double fX, double fY);
|
||||
STDMETHOD(PathCommandLinesTo)(SAFEARRAY* pPoints);
|
||||
STDMETHOD(PathCommandCurveTo)(double fX1, double fY1, double fX2, double fY2, double fX3, double fY3);
|
||||
STDMETHOD(PathCommandCurvesTo)(SAFEARRAY* pPoints);
|
||||
STDMETHOD(PathCommandArcTo)(double fX, double fY, double fWidth, double fHeight, double fStartAngle, double fSweepAngle);
|
||||
STDMETHOD(PathCommandClose)();
|
||||
STDMETHOD(PathCommandEnd)();
|
||||
STDMETHOD(DrawPath)(long nType);
|
||||
STDMETHOD(PathCommandStart)();
|
||||
STDMETHOD(PathCommandGetCurrentPoint)(double* fX, double* fY);
|
||||
|
||||
STDMETHOD(PathCommandText)(BSTR bsText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset);
|
||||
STDMETHOD(PathCommandTextEx)(BSTR bsUnicodeText, BSTR bsGidText, BSTR bsSourceCodeText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset, DWORD lFlags);
|
||||
|
||||
STDMETHOD(GetCommandParams)(double* dAngle, double* dLeft, double* dTop, double* dWidth, double* dHeight, DWORD* lFlags);
|
||||
STDMETHOD(SetCommandParams)(double dAngle, double dLeft, double dTop, double dWidth, double dHeight, DWORD lFlags);
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --------------------------------------------------
|
||||
STDMETHOD(DrawImage)(IUnknown* pInterface, double fX, double fY, double fWidth, double fHeight);
|
||||
STDMETHOD(DrawImageFromFile)(BSTR bstrVal, double fX, double fY, double fWidth, double fHeight);
|
||||
//------------------------------------------------------------------------------------------
|
||||
STDMETHOD(SetAdditionalParam)(BSTR ParamName, VARIANT ParamValue);
|
||||
STDMETHOD(GetAdditionalParam)(BSTR ParamName, VARIANT* ParamValue);
|
||||
|
||||
STDMETHOD(SetTransform)(double dA, double dB, double dC, double dD, double dE, double dF);
|
||||
STDMETHOD(GetTransform)(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF);
|
||||
STDMETHOD(ResetTransform)(void);
|
||||
STDMETHOD(get_ClipMode)(LONG* plMode);
|
||||
STDMETHOD(put_ClipMode)(LONG lMode);
|
||||
|
||||
// AVSRenderer2
|
||||
STDMETHOD(CommandLong)(LONG lCommand);
|
||||
STDMETHOD(CommandDouble)(double dCommand);
|
||||
STDMETHOD(CommandString)(BSTR bsCommand);
|
||||
STDMETHOD(CommandVariant)(VARIANT vCommand);
|
||||
|
||||
STDMETHOD(CommandLong2)(LONG lType, LONG lCommand);
|
||||
STDMETHOD(CommandDouble2)(LONG lType, double dCommand);
|
||||
STDMETHOD(CommandString2)(LONG lType, BSTR bsCommand);
|
||||
STDMETHOD(CommandVariant2)(LONG lType, VARIANT vCommand);
|
||||
|
||||
public:
|
||||
//IAVSDocxRenderer Methods
|
||||
STDMETHOD(Initialize)(BSTR bsXMLOptions);
|
||||
STDMETHOD(SetMetadata)(BSTR bsXMLOptions);
|
||||
STDMETHOD(CreateOfficeFile)(BSTR bsFileName, LONG lFileType);
|
||||
STDMETHOD(CloseFile)();
|
||||
|
||||
STDMETHOD(get_CommandRenderer)(IUnknown** ppunkRend)
|
||||
{
|
||||
if(NULL == ppunkRend)
|
||||
return S_FALSE;
|
||||
(*ppunkRend) = NULL;
|
||||
if(NULL == m_piCommandsRenderer)
|
||||
return S_OK;
|
||||
return m_piCommandsRenderer->QueryInterface(__uuidof(AVSGraphics::IAVSDocumentRenderer), (void**)&ppunkRend);
|
||||
}
|
||||
STDMETHOD(put_CommandRenderer)(IUnknown* ppunkRend)
|
||||
{
|
||||
RELEASEINTERFACE(m_piCommandsRenderer);
|
||||
if(NULL != ppunkRend)
|
||||
ppunkRend->QueryInterface(__uuidof( AVSGraphics::IAVSDocumentRenderer), (void**)&m_piCommandsRenderer);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void BaseInitialize(BSTR bsXMLOptions)
|
||||
{
|
||||
XmlUtils::CXmlNode oNode;
|
||||
if (oNode.FromXmlString((CString)bsXMLOptions))
|
||||
{
|
||||
XmlUtils::CXmlNode oNodeEbook;
|
||||
if (oNode.GetNode(_T("EbookOptions"), oNodeEbook))
|
||||
{
|
||||
m_oWriter.m_bIsSaveCover = (1 == oNodeEbook.ReadValueInt(_T("SaveCover"), 0));
|
||||
m_oWriter.m_bIsEmbeddedFonts = (1 == oNodeEbook.ReadValueInt(_T("FontEmbed"), 0));
|
||||
|
||||
m_oWriter.m_bIsSaveCover = !m_oWriter.m_bIsSaveCover;
|
||||
m_oWriter.m_bIsEmbeddedFonts = !m_oWriter.m_bIsEmbeddedFonts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHOD(put_TempDirectory)(BSTR bsFileName)
|
||||
{
|
||||
m_strTempDirectory = (CString)bsFileName;
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(get_TempDirectory)(BSTR* pbsFileName)
|
||||
{
|
||||
if (NULL == pbsFileName)
|
||||
return S_FALSE;
|
||||
|
||||
*pbsFileName = m_strTempDirectory.AllocSysString();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(put_SrcFileType)(LONG lType)
|
||||
{
|
||||
m_lSrcType = lType;
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(get_SrcFileType)(LONG* plType)
|
||||
{
|
||||
if (NULL == plType)
|
||||
return S_FALSE;
|
||||
|
||||
*plType = m_lSrcType;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
AVSINLINE void SendBeginCommandsToFlags()
|
||||
{
|
||||
if (c_nHeader == m_lCurrentCommandType)
|
||||
m_lCommandFlags += 100;
|
||||
if (c_nTextGraphicType == m_lCurrentCommandType)
|
||||
m_lCommandFlags += 1000;
|
||||
if (c_nTable == m_lCurrentCommandType)
|
||||
m_lCommandFlags += 10000;
|
||||
if (c_nFootnote == m_lCurrentCommandType)
|
||||
m_lCommandFlags += 100000;
|
||||
}
|
||||
AVSINLINE void SendEndCommandsToFlags(LONG lType)
|
||||
{
|
||||
if (c_nHeader == lType)
|
||||
m_lCommandFlags -= 100;
|
||||
if (c_nTextGraphicType == lType)
|
||||
m_lCommandFlags -= 1000;
|
||||
if (c_nTable == lType)
|
||||
m_lCommandFlags -= 10000;
|
||||
if (c_nFootnote == lType)
|
||||
m_lCommandFlags -= 100000;
|
||||
}
|
||||
AVSINLINE bool CheckNeedCommands()
|
||||
{
|
||||
//return true;
|
||||
return (0 == m_lCommandFlags) ? true : false;
|
||||
}
|
||||
|
||||
private:
|
||||
AVSINLINE void ApplyTransform(double d1, double d2, double d3, double d4, double d5, double d6)
|
||||
{
|
||||
m_oTransform.SetElements(d1, d2, d3, d4, d5, d6);
|
||||
m_dTransformAngle = m_oTransform.z_Rotation();
|
||||
}
|
||||
|
||||
void ApplyTransform2(double dAngle, double dLeft, double dTop, double dWidth, double dHeight, DWORD lFlags)
|
||||
{
|
||||
if ((dWidth <= 1) || (dHeight <= 1))
|
||||
lFlags = 0;
|
||||
|
||||
BOOL bFlipX = (0 != (c_nParamFlipX & lFlags));
|
||||
BOOL bFlipY = (0 != (c_nParamFlipY & lFlags));
|
||||
|
||||
double m11 = bFlipX ? -1.0 : 1.0;
|
||||
double m22 = bFlipY ? -1.0 : 1.0;
|
||||
|
||||
NSCommon::CMatrix oMatrix(1, 0, 0, 1, 0, 0);
|
||||
|
||||
if ((0 != dAngle) || (0 != lFlags))
|
||||
{
|
||||
double dCentreX = (dLeft + dWidth / 2.0);
|
||||
double dCentreY = (dTop + dHeight / 2.0);
|
||||
|
||||
oMatrix.Translate(-dCentreX, -dCentreY , Aggplus::MatrixOrderAppend);
|
||||
|
||||
oMatrix.Rotate(dAngle , Aggplus::MatrixOrderAppend);
|
||||
oMatrix.Scale(m11, m22 , Aggplus::MatrixOrderAppend);
|
||||
|
||||
oMatrix.Translate(dCentreX, dCentreY , Aggplus::MatrixOrderAppend);
|
||||
}
|
||||
|
||||
m_oTransform = oMatrix;
|
||||
m_dTransformAngle = m_oTransform.z_Rotation();
|
||||
}
|
||||
|
||||
void _SetFont()
|
||||
{
|
||||
if (NULL == m_pFontManager)
|
||||
{
|
||||
CoCreateInstance(__uuidof(AVSGraphics::CAVSFontManager), NULL, CLSCTX_ALL, __uuidof(AVSGraphics::IAVSFontManager), (void**)&m_pFontManager);
|
||||
m_pFontManager->Initialize(L"");
|
||||
}
|
||||
|
||||
double dPix = m_oFont.CharSpace * m_dDpiX / 25.4;
|
||||
|
||||
if (m_oInstalledFont.IsEqual(&m_oFont))
|
||||
{
|
||||
if (1 < m_dWidth)
|
||||
{
|
||||
m_pFontManager->SetCharSpacing(dPix);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_pFontManager->SetStringGID(m_oFont.StringGID);
|
||||
if (1 < m_dWidth)
|
||||
{
|
||||
m_pFontManager->SetCharSpacing(dPix);
|
||||
}
|
||||
|
||||
if (_T("") == m_oFont.Path)
|
||||
{
|
||||
BSTR bsName = m_oFont.Name.AllocSysString();
|
||||
m_pFontManager->LoadFontByName(bsName, (float)m_oFont.Size, m_oFont.GetStyle(), m_dDpiX, m_dDpiY);
|
||||
SysFreeString(bsName);
|
||||
}
|
||||
else
|
||||
{
|
||||
BSTR bsName = m_oFont.Path.AllocSysString();
|
||||
m_pFontManager->LoadFontFromFile(bsName, (float)m_oFont.Size, m_dDpiX, m_dDpiY, 0);
|
||||
SysFreeString(bsName);
|
||||
}
|
||||
|
||||
m_oInstalledFont = m_oFont;
|
||||
}
|
||||
|
||||
AVSINLINE void MoveTo(double& x, double& y)
|
||||
{
|
||||
m_oWriter.MoveTo(x, y);
|
||||
}
|
||||
AVSINLINE void LineTo(double& x, double& y)
|
||||
{
|
||||
m_oWriter.LineTo(x, y);
|
||||
}
|
||||
AVSINLINE void CurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
|
||||
{
|
||||
m_oWriter.CurveTo(x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
AVSINLINE void Close()
|
||||
{
|
||||
m_oWriter.Close();
|
||||
}
|
||||
|
||||
AVSINLINE void PathStart()
|
||||
{
|
||||
m_oWriter.BeginPath();
|
||||
}
|
||||
AVSINLINE void PathEnd()
|
||||
{
|
||||
m_oWriter.EndPath();
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
bool SaveCover()
|
||||
{
|
||||
if (NULL != m_piCommandsRenderer)
|
||||
{
|
||||
long nPageCount = 0;
|
||||
m_piCommandsRenderer->get_PageCount(&nPageCount);
|
||||
if (nPageCount > 0)
|
||||
{
|
||||
double dWidthMM = 0;
|
||||
double dHeightMM = 0;
|
||||
m_piCommandsRenderer->GetPageSize( 0, &dWidthMM, &dHeightMM );
|
||||
//
|
||||
LONG nHeight = 0;
|
||||
LONG nWidth = 0;
|
||||
if( 0 != dHeightMM )
|
||||
{
|
||||
nHeight = 1186;
|
||||
nWidth = nHeight * dWidthMM / dHeightMM;
|
||||
}
|
||||
MediaCore::IAVSUncompressedVideoFrame* piImage = NULL;
|
||||
AVSGraphics::IAVSGraphicsRenderer* piGraphicsRenderer = NULL;
|
||||
UpdateGdiPlusRenderer( dWidthMM, dHeightMM, &piImage, &piGraphicsRenderer );
|
||||
if( NULL != piGraphicsRenderer )
|
||||
{
|
||||
piGraphicsRenderer->NewPage();
|
||||
m_piCommandsRenderer->DrawPage( 0, piGraphicsRenderer );
|
||||
|
||||
IUnknown* punkFrame = NULL;
|
||||
piImage->QueryInterface(IID_IUnknown, (void**)&punkFrame);
|
||||
this->DrawImage(punkFrame, 0, 0, dWidthMM, dHeightMM);
|
||||
RELEASEINTERFACE(punkFrame);
|
||||
}
|
||||
|
||||
RELEASEINTERFACE(piGraphicsRenderer);
|
||||
RELEASEINTERFACE(piImage);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UpdateGdiPlusRenderer(double dWidthMm, double dHeightMm, MediaCore::IAVSUncompressedVideoFrame** piImage, AVSGraphics::IAVSGraphicsRenderer** piRend)
|
||||
{
|
||||
(*piImage) = NULL;
|
||||
(*piRend) = NULL;
|
||||
CoCreateInstance(__uuidof( MediaCore::CAVSUncompressedVideoFrame), NULL ,CLSCTX_INPROC_SERVER, __uuidof(MediaCore::IAVSUncompressedVideoFrame), (void **)piImage);
|
||||
AVSGraphics::IAVSFontManagerPtr piFontManager;
|
||||
piFontManager.CreateInstance( __uuidof(AVSGraphics::CAVSFontManager) );
|
||||
piFontManager->Initialize( L"" );
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dpi <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int nLOGPIXELSX = 96;
|
||||
int nLOGPIXELSY = 96;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
long nWidthPix = (long)(nLOGPIXELSX * dWidthMm / (25.4));
|
||||
long nHeightPix = (long)(nLOGPIXELSY * dHeightMm / (25.4));
|
||||
|
||||
if (nHeightPix > c_nMaxImageSize)
|
||||
{
|
||||
nWidthPix = (LONG)((double)nWidthPix * c_nMaxImageSize / nHeightPix);
|
||||
nHeightPix = c_nMaxImageSize;
|
||||
}
|
||||
|
||||
(*piImage)->put_Width(nWidthPix);
|
||||
(*piImage)->put_Height(nHeightPix);
|
||||
(*piImage)->put_Stride(0, nWidthPix * 4);
|
||||
|
||||
(*piImage)->put_AspectRatioX(nWidthPix);
|
||||
(*piImage)->put_AspectRatioY(nHeightPix);
|
||||
|
||||
(*piImage)->put_DataSize(4 * nWidthPix * nHeightPix);
|
||||
|
||||
(*piImage)->put_ColorSpace(64 + (1 << 31));
|
||||
(*piImage)->AllocateBuffer(-1);
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
(*piImage)->get_Buffer(&pBuffer);
|
||||
memset(pBuffer, 255, 4 * nWidthPix * nHeightPix);
|
||||
|
||||
CoCreateInstance(__uuidof( AVSGraphics::CAVSGraphicsRenderer), NULL ,CLSCTX_INPROC_SERVER, __uuidof(AVSGraphics::IAVSGraphicsRenderer), (void **)piRend);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FontManager
|
||||
VARIANT vtVariant;
|
||||
vtVariant.vt = VT_UNKNOWN;
|
||||
vtVariant.punkVal = piFontManager;
|
||||
(*piRend)->SetAdditionalParam( L"FontManager", vtVariant );
|
||||
|
||||
(*piRend)->put_Width(dWidthMm);
|
||||
(*piRend)->put_Height(dHeightMm);
|
||||
(*piRend)->CreateFromMediaData(*piImage, 0, 0, nWidthPix, nHeightPix );
|
||||
}
|
||||
};
|
||||
|
||||
510
AVSEBOOKWriter/Logic/EbookPage.h
Normal file
510
AVSEBOOKWriter/Logic/EbookPage.h
Normal file
@ -0,0 +1,510 @@
|
||||
#pragma once
|
||||
#include "../Common/FontManager.h"
|
||||
#include "Text.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class IEbookItem
|
||||
{
|
||||
public:
|
||||
enum EEBookItemType
|
||||
{
|
||||
ebitParagraph = 0,
|
||||
ebitTable = 1,
|
||||
ebitGraphic = 2,
|
||||
ebitNumbering = 3
|
||||
};
|
||||
|
||||
public:
|
||||
EEBookItemType m_eType;
|
||||
CDoubleRect m_rcBounds;
|
||||
bool m_bIsPageBreakAfter;
|
||||
virtual ~IEbookItem()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void ReadFromXml(XmlUtils::CXmlNode& oNode) = 0;
|
||||
virtual CString SaveToXml() = 0;
|
||||
};
|
||||
|
||||
class CEbookTable : public IEbookItem
|
||||
{
|
||||
public:
|
||||
CString m_strTableXml;
|
||||
|
||||
public:
|
||||
CEbookTable()
|
||||
{
|
||||
m_eType = ebitTable;
|
||||
m_strTableXml = _T("");
|
||||
m_bIsPageBreakAfter = false;
|
||||
}
|
||||
virtual ~CEbookTable()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void ReadFromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
m_strTableXml = oNode.GetXml();
|
||||
}
|
||||
virtual CString SaveToXml()
|
||||
{
|
||||
return m_strTableXml;
|
||||
}
|
||||
};
|
||||
|
||||
class CEbookGraphicObject : public IEbookItem
|
||||
{
|
||||
public:
|
||||
NSCommon::CImageInfo m_oInfo;
|
||||
LONG m_lWrapMode;
|
||||
|
||||
public:
|
||||
CEbookGraphicObject()
|
||||
{
|
||||
m_eType = ebitGraphic;
|
||||
m_lWrapMode = 0;
|
||||
m_bIsPageBreakAfter = false;
|
||||
}
|
||||
virtual ~CEbookGraphicObject()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void ReadFromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
m_lWrapMode = oNode.ReadAttributeInt(_T("wrap"));
|
||||
m_rcBounds.left = 0;
|
||||
m_rcBounds.top = 0;
|
||||
m_rcBounds.right = oNode.ReadAttributeDouble(_T("width"));
|
||||
m_rcBounds.bottom = oNode.ReadAttributeDouble(_T("height"));
|
||||
m_oInfo.m_lID = oNode.ReadAttributeInt(_T("id"));
|
||||
m_oInfo.m_eType = (_T("jpg") == oNode.GetAttribute(_T("type"))) ? NSCommon::itJPG : NSCommon::itPNG;
|
||||
}
|
||||
virtual CString SaveToXml()
|
||||
{
|
||||
CString strRet = _T("");
|
||||
strRet.Format(_T("<graphic wrap=\"%d\" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" id=\"%d\" type=\"%s\"/>"),
|
||||
m_lWrapMode, 0, 0, m_rcBounds.GetWidth(), m_rcBounds.GetHeight(), m_oInfo.m_lID,
|
||||
(NSCommon::itJPG == m_oInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
return strRet;
|
||||
}
|
||||
};
|
||||
|
||||
class CEbookParagraph : public IEbookItem
|
||||
{
|
||||
public:
|
||||
class CSpan
|
||||
{
|
||||
public:
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> - <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD>. <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>!!!
|
||||
CImageInfo m_oImageInfo;
|
||||
double m_dImageWidth;
|
||||
double m_dImageHeight;
|
||||
|
||||
double m_dX;
|
||||
double m_dWidthSpan;
|
||||
|
||||
double m_dBaselineOffset;
|
||||
|
||||
NSStructures::CFont m_oFont;
|
||||
NSStructures::CBrush m_oBrush;
|
||||
CTextItem m_oText;
|
||||
|
||||
public:
|
||||
CSpan() : m_oImageInfo(), m_oFont(), m_oBrush(), m_oText(10)
|
||||
{
|
||||
m_dImageWidth = 0;
|
||||
m_dImageHeight = 0;
|
||||
|
||||
m_dX = 0;
|
||||
m_dWidthSpan = 0;
|
||||
|
||||
m_dBaselineOffset = 0;
|
||||
}
|
||||
~CSpan()
|
||||
{
|
||||
}
|
||||
CSpan(const CSpan& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CSpan& operator=(const CSpan& oSrc)
|
||||
{
|
||||
m_oImageInfo = oSrc.m_oImageInfo;
|
||||
m_dImageWidth = oSrc.m_dImageWidth;
|
||||
m_dImageHeight = oSrc.m_dImageHeight;
|
||||
|
||||
m_dX = oSrc.m_dX;
|
||||
m_dWidthSpan = oSrc.m_dWidthSpan;
|
||||
m_dBaselineOffset = oSrc.m_dBaselineOffset;
|
||||
|
||||
m_oFont = oSrc.m_oFont;
|
||||
m_oBrush = oSrc.m_oBrush;
|
||||
m_oText = oSrc.m_oText;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CString ToXml()
|
||||
{
|
||||
if (-1 != m_oImageInfo.m_lID)
|
||||
{
|
||||
CString strRet = _T("");
|
||||
strRet.Format(_T("<image id=\"%d\" type=\"%d\"/>"), m_oImageInfo.m_lID, (int)m_oImageInfo.m_eType);
|
||||
return strRet;
|
||||
}
|
||||
CString strRet = _T("");
|
||||
strRet.Format(_T("<span baselineoffset=\"%d\">"), (LONG)m_dBaselineOffset);
|
||||
strRet += m_oFont.ToXmlString();
|
||||
strRet += m_oBrush.ToXmlString();
|
||||
strRet += m_oText.GetCString();
|
||||
strRet += _T("</span>");
|
||||
return strRet;
|
||||
}
|
||||
void FromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
if (_T("image") == oNode.GetName())
|
||||
{
|
||||
m_oImageInfo.m_lID = oNode.ReadAttributeInt(_T("id"));
|
||||
m_oImageInfo.m_eType = (NSCommon::ImageType)oNode.ReadAttributeInt(_T("type"));
|
||||
return;
|
||||
}
|
||||
|
||||
m_dBaselineOffset = oNode.ReadAttributeDouble(_T("baselineoffset"));
|
||||
XmlUtils::CXmlNodes oNodes;
|
||||
if (oNode.GetChilds(oNodes))
|
||||
{
|
||||
int nCount = oNodes.GetCount();
|
||||
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oNodeS;
|
||||
oNodes.GetAt(i, oNodeS);
|
||||
|
||||
CString sName = oNodeS.GetName();
|
||||
|
||||
if (_T("#text") == sName)
|
||||
{
|
||||
m_oText += (CString)oNodeS.GetXml();
|
||||
}
|
||||
else if (_T("font") == sName)
|
||||
{
|
||||
m_oFont.FromXmlNode(oNodeS);
|
||||
}
|
||||
else if (_T("brush") == sName)
|
||||
{
|
||||
m_oBrush.FromXmlNode(oNodeS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
class CLine
|
||||
{
|
||||
public:
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> - <20><> <20><><EFBFBD> Image <20><><EFBFBD><EFBFBD><EFBFBD>. <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
CImageInfo m_oImageInfo;
|
||||
CAtlList<CSpan> m_listSpans;
|
||||
|
||||
double m_dTop;
|
||||
double m_dBaselinePos;
|
||||
|
||||
public:
|
||||
CLine() : m_listSpans(), m_oImageInfo()
|
||||
{
|
||||
m_dTop = -1;
|
||||
m_dBaselinePos = -1;
|
||||
}
|
||||
~CLine()
|
||||
{
|
||||
}
|
||||
CLine(const CLine& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CLine& operator=(const CLine& oSrc)
|
||||
{
|
||||
m_dTop = oSrc.m_dTop;
|
||||
m_dBaselinePos = oSrc.m_dBaselinePos;
|
||||
|
||||
m_oImageInfo = oSrc.m_oImageInfo;
|
||||
m_listSpans.RemoveAll();
|
||||
|
||||
POSITION pos = oSrc.m_listSpans.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CSpan oSpan = oSrc.m_listSpans.GetNext(pos);
|
||||
m_listSpans.AddTail(oSpan);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
AVSINLINE bool CheckTitle()
|
||||
{
|
||||
if (-1 != m_oImageInfo.m_lID)
|
||||
return false;
|
||||
|
||||
POSITION pos = m_listSpans.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CSpan& oSpan = m_listSpans.GetNext(pos);
|
||||
if (oSpan.m_dBaselineOffset != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
LONG m_lTextAlign;
|
||||
LONG m_lStyle;
|
||||
LONG m_lNumberingLevel;
|
||||
|
||||
bool m_bIsComplete;
|
||||
CAtlList<CLine> m_arLines;
|
||||
|
||||
public:
|
||||
CEbookParagraph() : m_arLines()
|
||||
{
|
||||
m_eType = ebitParagraph;
|
||||
m_lTextAlign = 0;
|
||||
m_lStyle = 0;
|
||||
m_lNumberingLevel = 0;
|
||||
|
||||
m_bIsPageBreakAfter = false;
|
||||
|
||||
m_bIsComplete = true;
|
||||
}
|
||||
~CEbookParagraph()
|
||||
{
|
||||
}
|
||||
CEbookParagraph(const CEbookParagraph& oSrc)
|
||||
{
|
||||
m_eType = ebitParagraph;
|
||||
*this = oSrc;
|
||||
}
|
||||
CEbookParagraph& operator=(const CEbookParagraph& oSrc)
|
||||
{
|
||||
m_lTextAlign = oSrc.m_lTextAlign;
|
||||
m_lStyle = oSrc.m_lStyle;
|
||||
m_lNumberingLevel = oSrc.m_lNumberingLevel;
|
||||
|
||||
m_arLines.RemoveAll();
|
||||
POSITION pos = oSrc.m_arLines.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CLine oLine = oSrc.m_arLines.GetNext(pos);
|
||||
m_arLines.AddTail(oLine);
|
||||
}
|
||||
m_bIsComplete = oSrc.m_bIsComplete;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
m_lTextAlign = 0;
|
||||
m_lStyle = 0;
|
||||
m_lNumberingLevel = 0;
|
||||
|
||||
m_arLines.RemoveAll();
|
||||
}
|
||||
|
||||
virtual void ReadFromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
Clear();
|
||||
|
||||
m_lTextAlign = oNode.ReadAttributeInt(_T("align"));
|
||||
m_lStyle = oNode.ReadAttributeInt(_T("style"));
|
||||
m_lNumberingLevel = oNode.ReadAttributeInt(_T("level"));
|
||||
|
||||
m_arLines.AddTail();
|
||||
CLine& oLine = m_arLines.GetTail();
|
||||
|
||||
XmlUtils::CXmlNodes oNodes;
|
||||
if (oNode.GetNodes(_T("*"), oNodes))
|
||||
{
|
||||
int nCount = oNodes.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
oLine.m_listSpans.AddTail();
|
||||
CSpan& oSpan = oLine.m_listSpans.GetTail();
|
||||
|
||||
XmlUtils::CXmlNode oNodeSpan;
|
||||
oNodes.GetAt(i, oNodeSpan);
|
||||
oSpan.FromXml(oNodeSpan);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual CString SaveToXml()
|
||||
{
|
||||
CString strHead = _T("");
|
||||
strHead.Format(_T("<p align=\"%d\" style=\"%d\" level=\"%d\">"), m_lTextAlign, m_lStyle, m_lNumberingLevel);
|
||||
|
||||
CString strPar = strHead;
|
||||
|
||||
CSpan* pSpan = NULL;
|
||||
|
||||
POSITION posLine = m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
CLine& oLine = m_arLines.GetNext(posLine);
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (NULL == pSpan)
|
||||
pSpan = &oSpan;
|
||||
else if (pSpan->m_oFont.IsEqual(&oSpan.m_oFont) && pSpan->m_oBrush.IsEqual(&oSpan.m_oBrush)
|
||||
&& (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
pSpan->m_oText += oSpan.m_oText;
|
||||
}
|
||||
else
|
||||
{
|
||||
strPar += pSpan->ToXml();
|
||||
pSpan = &oSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != pSpan)
|
||||
{
|
||||
strPar += pSpan->ToXml();
|
||||
}
|
||||
|
||||
strPar += _T("</p>");
|
||||
return strPar;
|
||||
}
|
||||
|
||||
CString GetAllText()
|
||||
{
|
||||
CString strText = _T("");
|
||||
POSITION posLine = m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CLine& oLine = m_arLines.GetNext(posLine);
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (-1 != oSpan.m_oImageInfo.m_lID)
|
||||
continue;
|
||||
|
||||
strText += oSpan.m_oText.GetCString();
|
||||
}
|
||||
}
|
||||
return strText;
|
||||
}
|
||||
|
||||
AVSINLINE bool CheckTitle()
|
||||
{
|
||||
POSITION pos = m_arLines.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CLine& oLine = m_arLines.GetNext(pos);
|
||||
if (!oLine.CheckTitle())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
AVSINLINE void CheckShadows()
|
||||
{
|
||||
POSITION posLine = m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CLine& oLine = m_arLines.GetNext(posLine);
|
||||
NSEBook::CEbookParagraph::CSpan* pSpan = NULL;
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
POSITION posOld = posSpan;
|
||||
NSEBook::CEbookParagraph::CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (NULL == pSpan)
|
||||
pSpan = &oSpan;
|
||||
else if (oSpan.m_oText.IsEqualLast(pSpan->m_oText, ((pSpan->m_dX + pSpan->m_dWidthSpan - oSpan.m_dX) > 1) ? TRUE : FALSE))
|
||||
{
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD>!
|
||||
oLine.m_listSpans.RemoveAt(posOld);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class CEbookNumbering : public IEbookItem
|
||||
{
|
||||
public:
|
||||
CAtlArray<CEbookParagraph> m_arParagraphs;
|
||||
LONG m_lType;
|
||||
|
||||
public:
|
||||
CEbookNumbering() : m_arParagraphs()
|
||||
{
|
||||
m_lType = ebitNumbering;
|
||||
m_bIsPageBreakAfter = false;
|
||||
}
|
||||
CEbookNumbering(const CEbookNumbering& oSrc)
|
||||
{
|
||||
m_lType = ebitNumbering;
|
||||
*this = oSrc;
|
||||
}
|
||||
CEbookNumbering& operator=(const CEbookNumbering& oSrc)
|
||||
{
|
||||
m_lType = oSrc.m_lType;
|
||||
m_arParagraphs.Copy(oSrc.m_arParagraphs);
|
||||
return *this;
|
||||
}
|
||||
virtual ~CEbookNumbering()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void ReadFromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
m_arParagraphs.RemoveAll();
|
||||
|
||||
m_lType = oNode.ReadAttributeInt(_T("type"));
|
||||
XmlUtils::CXmlNodes oParagraphs;
|
||||
if (oNode.GetNodes(_T("p"), oParagraphs))
|
||||
{
|
||||
int nCount = oParagraphs.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oMem;
|
||||
oParagraphs.GetAt(i, oMem);
|
||||
m_arParagraphs.Add();
|
||||
m_arParagraphs[m_arParagraphs.GetCount() - 1].ReadFromXml(oMem);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual CString SaveToXml()
|
||||
{
|
||||
CString strXml = _T("");
|
||||
strXml.Format(_T("<num type=\"%d\">"), m_lType);
|
||||
|
||||
size_t nCount = m_arParagraphs.GetCount();
|
||||
for (size_t i = 0; i < nCount; ++i)
|
||||
{
|
||||
strXml += m_arParagraphs[i].SaveToXml();
|
||||
}
|
||||
strXml += _T("</num>");
|
||||
return strXml;
|
||||
}
|
||||
};
|
||||
}
|
||||
766
AVSEBOOKWriter/Logic/LogicItems.h
Normal file
766
AVSEBOOKWriter/Logic/LogicItems.h
Normal file
@ -0,0 +1,766 @@
|
||||
#pragma once
|
||||
#include "../Writers/Format.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CLogicTable : public ILogicItem
|
||||
{
|
||||
public:
|
||||
bool m_bIsEmbeddedFonts;
|
||||
LONG m_lDstFormat;
|
||||
NSEBook::CFormat* m_pFormat;
|
||||
NSCommon::CFontDstGenerator* m_pFontsDst;
|
||||
NSCommon::CFontManager* m_pFontManager;
|
||||
|
||||
CString m_strTableXml;
|
||||
public:
|
||||
CLogicTable()
|
||||
{
|
||||
m_eType = ILogicItem::elitTable;
|
||||
m_strTableXml = _T("");
|
||||
m_pFontsDst = NULL;
|
||||
m_pFontManager = NULL;
|
||||
m_pFormat = NULL;
|
||||
m_bIsEmbeddedFonts = false;
|
||||
m_lDstFormat = 0;
|
||||
}
|
||||
~CLogicTable()
|
||||
{
|
||||
}
|
||||
|
||||
virtual double GetPositionY()
|
||||
{
|
||||
return m_rcBounds.top;
|
||||
}
|
||||
virtual double GetPositionX()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LoadFromXml(CString strTable)
|
||||
{
|
||||
m_strTableXml = _T("");
|
||||
XmlUtils::CXmlNode oNode;
|
||||
if (oNode.FromXmlString(strTable))
|
||||
{
|
||||
NSCommon::CStringWriter oWriter;
|
||||
WriteTable(oNode, oWriter);
|
||||
m_strTableXml = oWriter.GetCString();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
void WriteTable(XmlUtils::CXmlNode& oNode, NSCommon::CStringWriter& oWriter)
|
||||
{
|
||||
oWriter.WriteStringC(_T("<table style=\"border-collapse:collapse;width:auto;align:left;margin-left:0cm;margin-bottom:0cm\">"));
|
||||
|
||||
XmlUtils::CXmlNode oNodeTable;
|
||||
if (oNode.GetNode(_T("fo:table-body"), oNodeTable))
|
||||
{
|
||||
XmlUtils::CXmlNodes oRows;
|
||||
if (oNodeTable.GetNodes(_T("fo:table-row"), oRows))
|
||||
{
|
||||
int nCount = oRows.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oRow;
|
||||
oRows.GetAt(i, oRow);
|
||||
WriteTR(oRow, oWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(_T("</table>"));
|
||||
}
|
||||
void WriteTR(XmlUtils::CXmlNode& oNode, NSCommon::CStringWriter& oWriter)
|
||||
{
|
||||
oWriter.WriteStringC(_T("<tr>"));
|
||||
|
||||
XmlUtils::CXmlNodes oColomns;
|
||||
if (oNode.GetNodes(_T("fo:table-cell"), oColomns))
|
||||
{
|
||||
int nCount = oColomns.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oColomn;
|
||||
oColomns.GetAt(i, oColomn);
|
||||
|
||||
CString strMergeV = oColomn.GetAttribute(_T("v-merge"));
|
||||
if (_T("continue") == strMergeV)
|
||||
continue;
|
||||
|
||||
WriteTD(oColomn, oWriter);
|
||||
}
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(_T("</tr>"));
|
||||
}
|
||||
void WriteTD(XmlUtils::CXmlNode& oNode, NSCommon::CStringWriter& oWriter)
|
||||
{
|
||||
oWriter.WriteStringC(_T("<td valign=\"top\""));
|
||||
|
||||
int colspan = oNode.ReadAttributeInt(_T("number-columns-spanned"), 1);
|
||||
int rowspan = oNode.ReadAttributeInt(_T("number-rows-spanned"), 1);
|
||||
|
||||
if (1 != colspan)
|
||||
{
|
||||
CString strMem = _T("");
|
||||
strMem.Format(_T(" colspan=\"%d\""), colspan);
|
||||
oWriter.WriteStringC(strMem);
|
||||
}
|
||||
if (1 != rowspan)
|
||||
{
|
||||
CString strMem = _T("");
|
||||
strMem.Format(_T(" rowspan=\"%d\""), rowspan);
|
||||
oWriter.WriteStringC(strMem);
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(_T(" style=\""));
|
||||
|
||||
oWriter.WriteStringC(_T("border:solid black 1.0pt;"));
|
||||
|
||||
oWriter.WriteStringC(_T("\">"));
|
||||
|
||||
XmlUtils::CXmlNodes oBlocks;
|
||||
if (oNode.GetNodes(_T("fo:block"), oBlocks))
|
||||
{
|
||||
int nCount = oBlocks.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oBlock;
|
||||
oBlocks.GetAt(i, oBlock);
|
||||
|
||||
WriteBlock(oBlock, oWriter);
|
||||
}
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(_T("</td>"));
|
||||
}
|
||||
void WriteBlock(XmlUtils::CXmlNode& oNode, NSCommon::CStringWriter& oWriter)
|
||||
{
|
||||
CString strAlign = oNode.GetAttribute(_T("text-align"), _T("left"));
|
||||
oWriter.WriteStringC(_T("<p style=\"text-align:") + strAlign + _T(";\">"));
|
||||
|
||||
XmlUtils::CXmlNodes oChilds;
|
||||
if (oNode.GetChilds(oChilds))
|
||||
{
|
||||
int nCount = oChilds.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oItem;
|
||||
oChilds.GetAt(i, oItem);
|
||||
|
||||
CString strItem = oItem.GetName();
|
||||
|
||||
if (_T("fo:inline") == strItem)
|
||||
{
|
||||
XmlUtils::CXmlNode oNodeStyle = oItem.ReadNode(_T("style-complete"));
|
||||
XmlUtils::CXmlNode oNodeText = oItem.ReadNode(_T("text"));
|
||||
|
||||
NSEBook::CEbookParagraph::CSpan oSpan;
|
||||
oSpan.m_oText += oNodeText.GetTextExt();
|
||||
|
||||
oSpan.m_oFont.Name = oNodeStyle.GetAttribute(_T("font-family"));
|
||||
oSpan.m_oFont.Bold = (_T("bold") == oNodeStyle.GetAttribute(_T("font-weight")));
|
||||
oSpan.m_oFont.Italic = (_T("italic") == oNodeStyle.GetAttribute(_T("font-style")));
|
||||
|
||||
CString strSize = oNodeStyle.GetAttribute(_T("font-size"));
|
||||
oSpan.m_oFont.Size = 0;
|
||||
if (2 < strSize.GetLength())
|
||||
{
|
||||
strSize.Delete(strSize.GetLength() - 2, 2);
|
||||
oSpan.m_oFont.Size = XmlUtils::GetDouble(strSize);
|
||||
}
|
||||
if (0 == oSpan.m_oFont.Size)
|
||||
oSpan.m_oFont.Size = 10;
|
||||
|
||||
m_pFontsDst->AddFont(&oSpan.m_oFont, true, m_pFontManager);
|
||||
|
||||
CString strStyle1 = _T("");
|
||||
CString strStyle2 = _T("");
|
||||
|
||||
if (m_bIsEmbeddedFonts)
|
||||
{
|
||||
CString strName = oSpan.m_oFont.Name;
|
||||
strName.Replace(_T(" "), _T("_avs_space_"));
|
||||
|
||||
strStyle1 = (_T("<span style=\"font-family:") + strName + _T(";"));
|
||||
if (oSpan.m_oFont.Bold)
|
||||
strStyle1 += _T("font-weight:bold;");
|
||||
else
|
||||
strStyle1 += _T("font-weight:normal;");
|
||||
|
||||
if (oSpan.m_oFont.Italic)
|
||||
strStyle1 += _T("font-style:italic;\">");
|
||||
else
|
||||
strStyle1 += _T("font-style:normal;\">");
|
||||
|
||||
strStyle2 = _T("</span>");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oSpan.m_oFont.Bold)
|
||||
{
|
||||
strStyle1 += _T("<b>");
|
||||
strStyle2 += _T("</b>");
|
||||
}
|
||||
if (oSpan.m_oFont.Italic)
|
||||
{
|
||||
strStyle1 += _T("<i>");
|
||||
strStyle2 = (_T("</i>") + strStyle2);
|
||||
}
|
||||
if (oSpan.m_oFont.Underline != 0)
|
||||
{
|
||||
strStyle1 += _T("<u>");
|
||||
strStyle2 = (_T("</u>") + strStyle2);
|
||||
}
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(strStyle1);
|
||||
if (2 != m_lDstFormat)
|
||||
{
|
||||
oWriter.WriteTextXML(oSpan.m_oText);
|
||||
}
|
||||
else
|
||||
{
|
||||
oWriter.WriteTextHTML(oSpan.m_oText);
|
||||
}
|
||||
oWriter.WriteStringC(strStyle2);
|
||||
}
|
||||
else if (_T("fo:alternate-content") == strItem)
|
||||
{
|
||||
XmlUtils::CXmlNode node1;
|
||||
if (oItem.GetNode(_T("fo:property"), node1))
|
||||
{
|
||||
XmlUtils::CXmlNode node2;
|
||||
if (node1.GetNode(_T("fo:graphic"), node2))
|
||||
{
|
||||
XmlUtils::CXmlNode node3;
|
||||
if (node2.GetNode(_T("fo:source"), node3))
|
||||
{
|
||||
CString strFile = node3.GetAttribute(_T("dir"));
|
||||
strFile += _T("\\word\\");
|
||||
CString strName = node3.GetTextExt();
|
||||
strName.Replace(TCHAR('/'), TCHAR('\\'));
|
||||
|
||||
strFile += strName;
|
||||
|
||||
CFile oFile;
|
||||
HRESULT hr = oFile.OpenFile(strFile);
|
||||
oFile.CloseFile();
|
||||
|
||||
if (S_OK == hr)
|
||||
{
|
||||
double _x = 0;
|
||||
double _y = 0;
|
||||
double _w = 10000;
|
||||
double _h = 10000;
|
||||
|
||||
NSCommon::CImageInfo oInfo = m_pFormat->m_oImageManager.WriteImage(strFile, _x, _y, _w, _h);
|
||||
|
||||
if (0 == m_lDstFormat)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<img src=\"media/image%d.%s\" alt=\"\"/>"), oInfo.m_lID,
|
||||
(NSCommon::itJPG == oInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
oWriter.WriteStringC(strImage);
|
||||
}
|
||||
else if (1 == m_lDstFormat)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<image xlink:href=\"#image%d.%s\"/>"), oInfo.m_lID,
|
||||
(NSCommon::itJPG == oInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
oWriter.WriteStringC(strImage);
|
||||
}
|
||||
else if (2 == m_lDstFormat)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<img recindex=\"%d\" align=\"baseline\" alt=\"\"/>"), oInfo.m_lID);
|
||||
oWriter.WriteStringC(strImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(_T("</p>"));
|
||||
}
|
||||
};
|
||||
|
||||
class IGraphicCommand
|
||||
{
|
||||
public:
|
||||
enum EGraphicCommandType
|
||||
{
|
||||
egctPath = 0,
|
||||
egctText = 1
|
||||
};
|
||||
|
||||
public:
|
||||
EGraphicCommandType m_eType;
|
||||
|
||||
public:
|
||||
IGraphicCommand()
|
||||
{
|
||||
m_eType = egctPath;
|
||||
}
|
||||
};
|
||||
|
||||
class CItemPath : public IGraphicCommand
|
||||
{
|
||||
private:
|
||||
class CPathMeta
|
||||
{
|
||||
private:
|
||||
enum PathCommand
|
||||
{
|
||||
// pathcommands
|
||||
pcMoveTo = 0,
|
||||
pcLineTo = 1,
|
||||
pcCurveTo = 2,
|
||||
pcClose = 3
|
||||
};
|
||||
private:
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE* m_pBuffer;
|
||||
BYTE* m_pBufferMem;
|
||||
|
||||
size_t m_lPosition;
|
||||
size_t m_lSize;
|
||||
|
||||
public:
|
||||
CPathMeta()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
~CPathMeta()
|
||||
{
|
||||
RELEASEARRAYOBJECTS(m_pBuffer);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
m_lSize = 0;
|
||||
m_lPosition = 0;
|
||||
|
||||
m_pBuffer = NULL;
|
||||
}
|
||||
|
||||
AVSINLINE void CheckBufferSize(size_t lPlus)
|
||||
{
|
||||
if (NULL != m_pBuffer)
|
||||
{
|
||||
size_t nNewSize = m_lPosition + lPlus;
|
||||
|
||||
if (nNewSize >= m_lSize)
|
||||
{
|
||||
while (nNewSize >= m_lSize)
|
||||
{
|
||||
m_lSize *= 2;
|
||||
}
|
||||
|
||||
BYTE* pNew = new BYTE[m_lSize];
|
||||
memcpy(pNew, m_pBuffer, m_lPosition);
|
||||
|
||||
RELEASEARRAYOBJECTS(m_pBuffer);
|
||||
m_pBuffer = pNew;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lSize = 1000;
|
||||
m_pBuffer = new BYTE[m_lSize];
|
||||
|
||||
CheckBufferSize(lPlus);
|
||||
}
|
||||
}
|
||||
|
||||
AVSINLINE void WriteCommandType(const PathCommand& eType)
|
||||
{
|
||||
CheckBufferSize(sizeof(BYTE));
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eType;
|
||||
m_lPosition += sizeof(BYTE);
|
||||
}
|
||||
inline void WriteDouble(const double& dValue)
|
||||
{
|
||||
CheckBufferSize(sizeof(double));
|
||||
|
||||
*((double*)(m_pBuffer + m_lPosition)) = dValue;
|
||||
m_lPosition += sizeof(double);
|
||||
}
|
||||
inline void WriteBYTE(const PathCommand& eType, const BYTE& lValue)
|
||||
{
|
||||
CheckBufferSize(2 * sizeof(BYTE));
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eType;
|
||||
m_lPosition += sizeof(BYTE);
|
||||
|
||||
*(m_pBuffer + m_lPosition) = lValue;
|
||||
m_lPosition += sizeof(BYTE);
|
||||
}
|
||||
inline void WriteLONG(const PathCommand& eType, const LONG& lValue)
|
||||
{
|
||||
CheckBufferSize(sizeof(BYTE) + sizeof(LONG));
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eType;
|
||||
m_lPosition += sizeof(BYTE);
|
||||
|
||||
*((LONG*)(m_pBuffer + m_lPosition)) = lValue;
|
||||
m_lPosition += sizeof(LONG);
|
||||
}
|
||||
inline void WriteDouble(const PathCommand& eType, const double& dValue)
|
||||
{
|
||||
CheckBufferSize(sizeof(BYTE) + sizeof(double));
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eType;
|
||||
m_lPosition += sizeof(BYTE);
|
||||
|
||||
*((double*)(m_pBuffer + m_lPosition)) = dValue;
|
||||
m_lPosition += sizeof(double);
|
||||
}
|
||||
inline void Write(const PathCommand& eCommand, const double& f1, const double& f2)
|
||||
{
|
||||
size_t lMem = sizeof(BYTE) + 2 * sizeof(double);
|
||||
|
||||
CheckBufferSize(lMem);
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += sizeof(BYTE);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f1; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f2; m_lPosition += sizeof(double);
|
||||
}
|
||||
|
||||
inline void Write(const PathCommand& eCommand, const double& f1, const double& f2, const double& f3, const double& f4, const double& f5, const double& f6)
|
||||
{
|
||||
size_t lMem = sizeof(BYTE) + 6 * sizeof(double);
|
||||
|
||||
CheckBufferSize(lMem);
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += sizeof(BYTE);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f1; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f2; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f3; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f4; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f5; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f6; m_lPosition += sizeof(double);
|
||||
}
|
||||
public:
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
AVSINLINE void _MoveTo(double fX, double fY)
|
||||
{
|
||||
Write(pcMoveTo, fX, fY);
|
||||
}
|
||||
AVSINLINE void _LineTo(double fX, double fY)
|
||||
{
|
||||
Write(pcLineTo, fX, fY);
|
||||
}
|
||||
AVSINLINE void _CurveTo(double fX1, double fY1, double fX2, double fY2, double fX3, double fY3)
|
||||
{
|
||||
Write(pcCurveTo, fX1, fY1, fX2, fY2, fX3, fY3);
|
||||
}
|
||||
AVSINLINE void _Close()
|
||||
{
|
||||
WriteCommandType(pcClose);
|
||||
}
|
||||
public:
|
||||
AVSINLINE LONG ReadLONG()
|
||||
{
|
||||
LONG l = *((LONG*)m_pBufferMem);
|
||||
m_pBufferMem += sizeof(LONG);
|
||||
return l;
|
||||
}
|
||||
AVSINLINE BYTE ReadByte()
|
||||
{
|
||||
BYTE l = *m_pBufferMem;
|
||||
++m_pBufferMem;
|
||||
return l;
|
||||
}
|
||||
AVSINLINE double ReadDouble()
|
||||
{
|
||||
double l = *((double*)m_pBufferMem);
|
||||
m_pBufferMem += sizeof(double);
|
||||
return l;
|
||||
}
|
||||
public:
|
||||
BOOL Draw(IAVSRenderer* pRenderer)
|
||||
{
|
||||
if (NULL == pRenderer)
|
||||
return FALSE;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...
|
||||
m_pBufferMem = m_pBuffer;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...
|
||||
// (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> - <20> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (!!!) <20><><EFBFBD>)
|
||||
PathCommand eCurCommand;
|
||||
|
||||
HRESULT hRes = S_OK;
|
||||
while (m_lPosition > ((size_t)(m_pBufferMem - m_pBuffer)))
|
||||
{
|
||||
eCurCommand = (PathCommand)ReadByte();
|
||||
|
||||
switch (eCurCommand)
|
||||
{
|
||||
case pcMoveTo:
|
||||
{
|
||||
double fX = ReadDouble();
|
||||
double fY = ReadDouble();
|
||||
|
||||
hRes = pRenderer->PathCommandMoveTo(fX, fY);
|
||||
|
||||
break;
|
||||
}
|
||||
case pcLineTo:
|
||||
{
|
||||
double fX = ReadDouble();
|
||||
double fY = ReadDouble();
|
||||
|
||||
hRes = pRenderer->PathCommandLineTo(fX, fY);
|
||||
|
||||
break;
|
||||
}
|
||||
case pcCurveTo:
|
||||
{
|
||||
double fX1 = ReadDouble();
|
||||
double fY1 = ReadDouble();
|
||||
double fX2 = ReadDouble();
|
||||
double fY2 = ReadDouble();
|
||||
double fX3 = ReadDouble();
|
||||
double fY3 = ReadDouble();
|
||||
|
||||
hRes = pRenderer->PathCommandCurveTo(fX1, fY1, fX2, fY2, fX3, fY3);
|
||||
|
||||
break;
|
||||
}
|
||||
case pcClose:
|
||||
{
|
||||
hRes = pRenderer->PathCommandClose();
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
return FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
if (S_OK != hRes)
|
||||
break;
|
||||
}
|
||||
return (S_OK == hRes);
|
||||
}
|
||||
};
|
||||
public:
|
||||
NSStructures::CPen m_oPen;
|
||||
NSStructures::CBrush m_oBrush;
|
||||
|
||||
LONG m_lType;
|
||||
CDoubleRect m_rcBounds;
|
||||
CPathMeta m_oGeometry;
|
||||
|
||||
public:
|
||||
CItemPath()
|
||||
{
|
||||
m_rcBounds.left = 50000;
|
||||
m_rcBounds.right = -1;
|
||||
m_rcBounds.top = 50000;
|
||||
m_rcBounds.bottom = -1;
|
||||
}
|
||||
~CItemPath()
|
||||
{
|
||||
}
|
||||
};
|
||||
class CItemText
|
||||
{
|
||||
public:
|
||||
NSStructures::CBrush m_oBrush;
|
||||
NSStructures::CFont m_oFont;
|
||||
_bstr_t m_bsText;
|
||||
_bstr_t m_bsGid;
|
||||
|
||||
public:
|
||||
CItemText() : m_bsText(), m_bsGid()
|
||||
{
|
||||
}
|
||||
~CItemText()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class CLogicGraphic : public ILogicItem
|
||||
{
|
||||
public:
|
||||
CAtlList<IGraphicCommand*> m_arCommands;
|
||||
|
||||
public:
|
||||
CLogicGraphic()
|
||||
{
|
||||
m_eType = ILogicItem::elitGraphic;
|
||||
}
|
||||
~CLogicGraphic()
|
||||
{
|
||||
}
|
||||
|
||||
virtual double GetPositionY()
|
||||
{
|
||||
return m_rcBounds.top;
|
||||
}
|
||||
virtual double GetPositionX()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
class CLogicImage : public ILogicItem
|
||||
{
|
||||
public:
|
||||
CImageInfo m_oImageInfo;
|
||||
|
||||
public:
|
||||
CLogicImage()
|
||||
{
|
||||
m_oImageInfo.m_lID = -1;
|
||||
m_eType = ILogicItem::elitGraphic;
|
||||
}
|
||||
~CLogicImage()
|
||||
{
|
||||
}
|
||||
|
||||
virtual double GetPositionY()
|
||||
{
|
||||
return m_rcBounds.top;
|
||||
}
|
||||
virtual double GetPositionX()
|
||||
{
|
||||
return m_rcBounds.left;
|
||||
}
|
||||
};
|
||||
|
||||
class CLogicParagraph : public ILogicItem
|
||||
{
|
||||
public:
|
||||
CEbookParagraph m_oParagraph;
|
||||
|
||||
public:
|
||||
CLogicParagraph()
|
||||
{
|
||||
m_eType = elitTextParagraph;
|
||||
}
|
||||
CLogicParagraph(const CEbookParagraph& oSrc)
|
||||
{
|
||||
m_eType = elitTextParagraph;
|
||||
m_oParagraph = oSrc;
|
||||
}
|
||||
~CLogicParagraph()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual double GetPositionY()
|
||||
{
|
||||
return m_rcBounds.top;
|
||||
}
|
||||
virtual double GetPositionX()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class ILogicPage
|
||||
{
|
||||
public:
|
||||
NSStructures::CPen* m_pPen;
|
||||
NSStructures::CBrush* m_pBrush;
|
||||
NSStructures::CFont* m_pFont;
|
||||
NSStructures::CShadow* m_pShadow;
|
||||
NSStructures::CEdgeText* m_pEdgeText;
|
||||
|
||||
NSCommon::CMatrix* m_pTransform;
|
||||
AVSGraphics::IAVSGraphicSimpleComverter* m_pSimpleGraphicsConverter;
|
||||
|
||||
double m_dWidth;
|
||||
double m_dHeight;
|
||||
|
||||
CImageManager m_oManager;
|
||||
|
||||
LONG m_lCurrentCommand;
|
||||
CAtlList<ILogicItem*> m_arItems;
|
||||
|
||||
CImageManager* m_pImageManager;
|
||||
|
||||
NSCommon::CFontDstGenerator m_oFontsGen;
|
||||
NSCommon::CFontManager m_oFontManager;
|
||||
|
||||
CImageInfo m_oInfoWatermark;
|
||||
CDoubleRect m_oRectWatermark;
|
||||
bool m_bIsDumpWatermark;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~ILogicPage()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void ConvertToEbookPage(NSEBook::CFormat& oFormat) = 0;
|
||||
virtual void Clear() = 0;
|
||||
|
||||
virtual void MoveTo(double& x, double& y) = 0;
|
||||
virtual void LineTo(double& x, double& y) = 0;
|
||||
virtual void CurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3) = 0;
|
||||
virtual void Close() = 0;
|
||||
virtual void BeginPath() = 0;
|
||||
virtual void EndPath() = 0;
|
||||
virtual void DrawPath(LONG lType) = 0;
|
||||
|
||||
virtual void WriteText(BSTR& bsText, BSTR& bsGid, double& x, double& y, double& width, double& height, double& baselineoffset) = 0;
|
||||
|
||||
virtual void WriteTable(NSEBook::ILogicItem* pItem) = 0;
|
||||
virtual void BeginShape() = 0;
|
||||
virtual void EndShape() = 0;
|
||||
|
||||
virtual void WriteImage(IUnknown* punkImage, double& x, double& y, double& width, double& height) = 0;
|
||||
virtual void WriteImage(CString strFilePath, double& x, double& y, double& width, double& height) = 0;
|
||||
|
||||
virtual void BeginPage() = 0;
|
||||
virtual void EndPage() = 0;
|
||||
virtual void CloseFile(NSEBook::CFormat& oFormat) = 0;
|
||||
|
||||
virtual void InitProp() = 0;
|
||||
virtual void WritePagePreak()
|
||||
{
|
||||
if (0 == m_arItems.GetCount())
|
||||
return;
|
||||
|
||||
ILogicItem* pItem = m_arItems.GetTail();
|
||||
if (NULL != pItem)
|
||||
pItem->m_bIsPageBreakAfter = true;
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void CheckWatermark(CFormat& oFormat)
|
||||
{
|
||||
if (m_bIsDumpWatermark && (-1 != m_oInfoWatermark.m_lID))
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> watermark
|
||||
CEbookGraphicObject* pObject = new CEbookGraphicObject();
|
||||
pObject->m_oInfo = m_oInfoWatermark;
|
||||
pObject->m_rcBounds = m_oRectWatermark;
|
||||
|
||||
if (0 == oFormat.m_listSections.GetCount())
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
oFormat.m_listSections.AddTail();
|
||||
}
|
||||
CSection& oSection = oFormat.m_listSections.GetTail();
|
||||
oSection.m_arItems.AddTail(pObject);
|
||||
}
|
||||
m_bIsDumpWatermark = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
0
AVSEBOOKWriter/Logic/LogicPage.cpp
Normal file
0
AVSEBOOKWriter/Logic/LogicPage.cpp
Normal file
3
AVSEBOOKWriter/Logic/LogicPage.h
Normal file
3
AVSEBOOKWriter/Logic/LogicPage.h
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
#include "LogicPagePDF.h"
|
||||
#include "LogicPageDOCX.h"
|
||||
883
AVSEBOOKWriter/Logic/LogicPageDOCX.h
Normal file
883
AVSEBOOKWriter/Logic/LogicPageDOCX.h
Normal file
@ -0,0 +1,883 @@
|
||||
#pragma once
|
||||
#include "LogicItems.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CBaseWriter
|
||||
{
|
||||
public:
|
||||
virtual void WriteShape(IUnknown* punkImage, double& x, double& y, double& width, double& height) = 0;
|
||||
};
|
||||
|
||||
|
||||
const double c_dSpaceW = 0.5;
|
||||
class CTextSmart
|
||||
{
|
||||
public:
|
||||
CFontManager* m_pFontManager;
|
||||
CFontDstGenerator* m_pFontsDst;
|
||||
|
||||
double m_dDpiX;
|
||||
double m_dDpiY;
|
||||
|
||||
NSStructures::CPen* m_pPen;
|
||||
NSStructures::CBrush* m_pBrush;
|
||||
NSStructures::CFont* m_pFont;
|
||||
|
||||
NSCommon::CMatrix* m_pTransform;
|
||||
|
||||
CEbookParagraph m_oParagraph;
|
||||
CTextItem m_oTextItem;
|
||||
|
||||
private:
|
||||
double m_dEpsX;
|
||||
double m_dEpsY;
|
||||
|
||||
public:
|
||||
CTextSmart() : m_pFontManager(NULL), m_oTextItem(10)
|
||||
{
|
||||
m_dEpsX = 0.5;
|
||||
m_dEpsY = 0.5;
|
||||
|
||||
m_pPen = NULL;
|
||||
m_pBrush = NULL;
|
||||
m_pFont = NULL;
|
||||
|
||||
m_pTransform = NULL;
|
||||
|
||||
m_pFontsDst = NULL;
|
||||
}
|
||||
|
||||
void SetParams(NSStructures::CPen* pPen, NSStructures::CBrush* pBrush, NSStructures::CFont* pFont, NSCommon::CMatrix* pTransform)
|
||||
{
|
||||
m_pPen = pPen;
|
||||
m_pBrush = pBrush;
|
||||
m_pFont = pFont;
|
||||
|
||||
m_pFontManager->m_pFont = pFont;
|
||||
m_pFontManager->m_pTransform = pTransform;
|
||||
m_pTransform = pTransform;
|
||||
}
|
||||
|
||||
~CTextSmart()
|
||||
{
|
||||
}
|
||||
|
||||
void NewPage(double& dDpiX, double& dDpiY)
|
||||
{
|
||||
m_dDpiX = dDpiX;
|
||||
m_dDpiY = dDpiY;
|
||||
|
||||
m_pPen->SetDefaultParams();
|
||||
m_pBrush->SetDefaultParams();
|
||||
m_pFont->SetDefaultParams();
|
||||
|
||||
m_oParagraph.Clear();
|
||||
}
|
||||
|
||||
void NewDocument()
|
||||
{
|
||||
m_pPen->SetDefaultParams();
|
||||
m_pBrush->SetDefaultParams();
|
||||
m_pFont->SetDefaultParams();
|
||||
}
|
||||
|
||||
CEbookParagraph::CLine& GetCurrentLine()
|
||||
{
|
||||
if (0 == m_oParagraph.m_arLines.GetCount())
|
||||
m_oParagraph.m_arLines.AddTail();
|
||||
|
||||
return m_oParagraph.m_arLines.GetTail();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void CommandText(double& x, double& y, double& width, double& height, double& baselineoffset, double& dCurrentBaselineOffset)
|
||||
{
|
||||
double dScaleFont = ((m_pTransform->m_agg_mtx.sx + m_pTransform->m_agg_mtx.sy) / 2);
|
||||
BOOL bIsFontChanged = !m_pFontManager->m_oFont.m_oFont.IsEqual2(m_pFont, dScaleFont);
|
||||
|
||||
BOOL bIsTextDecorationChanged = ((m_pFontManager->m_oFont.m_oFont.Underline != m_pFont->Underline) ||
|
||||
(m_pFontManager->m_oFont.m_oFont.Strikeout != m_pFont->Strikeout));
|
||||
|
||||
if (bIsFontChanged)
|
||||
{
|
||||
m_pFontManager->m_oFont.m_oFont = *m_pFont;
|
||||
m_pFontManager->m_oFont.m_oFont.Size *= dScaleFont;
|
||||
}
|
||||
else if (bIsTextDecorationChanged)
|
||||
{
|
||||
m_pFontManager->m_oFont.m_oFont.Underline = m_pFont->Underline;
|
||||
m_pFontManager->m_oFont.m_oFont.Strikeout = m_pFont->Strikeout;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> m_pFont
|
||||
m_pFontManager->m_strCurrentPickFont = _T("");
|
||||
|
||||
if (0 == width)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>?? <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>??
|
||||
m_pFontManager->LoadCurrentFont();
|
||||
|
||||
double dOffset = m_pFontManager->m_oFont.m_dBaselineOffsetHTML;
|
||||
dOffset *= (m_dDpiY / 72.0);
|
||||
|
||||
y -= dOffset;
|
||||
baselineoffset = dOffset;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
double _x = 0;
|
||||
double _y = 0;
|
||||
double _w = 0;
|
||||
double _h = 0;
|
||||
|
||||
LONG lGid = m_pFontManager->GetStringGid();
|
||||
m_pFontManager->SetStringGid(0);
|
||||
m_pFontManager->MeasureStringPix(m_oTextItem.GetCString(), x, y, _x, _y, _w, _h, CFontManager::MeasureTypePosition);
|
||||
m_pFontManager->SetStringGid(lGid);
|
||||
|
||||
width = _w;
|
||||
height = _h;
|
||||
}
|
||||
|
||||
CEbookParagraph::CLine& oCurrentLine = GetCurrentLine();
|
||||
|
||||
double dYPos = y + baselineoffset;
|
||||
LONG lCountWords = (LONG)oCurrentLine.m_listSpans.GetCount();
|
||||
|
||||
m_pFontsDst->AddFont(m_pFont, bIsFontChanged, m_pFontManager);
|
||||
if (0 == lCountWords)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>, <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
oCurrentLine.m_listSpans.AddTail();
|
||||
CEbookParagraph::CSpan& oSpan = oCurrentLine.m_listSpans.GetTail();
|
||||
|
||||
//oSpan.m_oFont = m_oFontManager.m_oFont.m_oFont;
|
||||
//oSpan.m_oFont.Name = m_oFontManager.m_strCurrentPickFont;
|
||||
//oSpan.m_oFont.SetStyle(m_oFontManager.m_lCurrentPictFontStyle);
|
||||
oSpan.m_oFont = *m_pFont;
|
||||
|
||||
oSpan.m_oBrush = *m_pBrush;
|
||||
oSpan.m_oText = m_oTextItem;
|
||||
oSpan.m_dX = x;
|
||||
oSpan.m_dWidthSpan = width;
|
||||
oSpan.m_dBaselineOffset = dCurrentBaselineOffset;
|
||||
return;
|
||||
}
|
||||
|
||||
CEbookParagraph::CSpan& oTail = oCurrentLine.m_listSpans.GetTail();
|
||||
double dRight = oTail.m_dX + oTail.m_dWidthSpan;
|
||||
if (oTail.m_oImageInfo.m_lID != -1)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
oCurrentLine.m_listSpans.AddTail();
|
||||
CEbookParagraph::CSpan& oSpan = oCurrentLine.m_listSpans.GetTail();
|
||||
|
||||
//oSpan.m_oFont = m_oFontManager.m_oFont.m_oFont;
|
||||
//oSpan.m_oFont.Name = m_oFontManager.m_strCurrentPickFont;
|
||||
//oSpan.m_oFont.SetStyle(m_oFontManager.m_lCurrentPictFontStyle);
|
||||
oSpan.m_oFont = *m_pFont;
|
||||
|
||||
oSpan.m_oBrush = *m_pBrush;
|
||||
oSpan.m_oText = m_oTextItem;
|
||||
oSpan.m_dX = x;
|
||||
oSpan.m_dWidthSpan = width;
|
||||
oSpan.m_dBaselineOffset = dCurrentBaselineOffset;
|
||||
|
||||
if (c_dSpaceW < abs(oTail.m_dX + oTail.m_dWidthSpan - x))
|
||||
{
|
||||
// <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>!!!
|
||||
oSpan.m_oText.AddSpaceFirst();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (!bIsFontChanged && oTail.m_oBrush.IsEqual(m_pBrush) && !bIsTextDecorationChanged && (oTail.m_dBaselineOffset == dCurrentBaselineOffset))
|
||||
{
|
||||
if (c_dSpaceW < abs(oTail.m_dX + oTail.m_dWidthSpan - x))
|
||||
{
|
||||
// <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>!!!
|
||||
oTail.m_oText.AddSpace();
|
||||
}
|
||||
|
||||
oTail.m_oText += m_oTextItem;
|
||||
oTail.m_dWidthSpan = (x + width - oTail.m_dX);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c_dSpaceW < abs(oTail.m_dX + oTail.m_dWidthSpan - x))
|
||||
{
|
||||
// <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>!!!
|
||||
oTail.m_oText.AddSpace();
|
||||
}
|
||||
|
||||
oCurrentLine.m_listSpans.AddTail();
|
||||
CEbookParagraph::CSpan& oSpan = oCurrentLine.m_listSpans.GetTail();
|
||||
|
||||
//oSpan.m_oFont = m_oFontManager.m_oFont.m_oFont;
|
||||
//oSpan.m_oFont.Name = m_oFontManager.m_strCurrentPickFont;
|
||||
//oSpan.m_oFont.SetStyle(m_oFontManager.m_lCurrentPictFontStyle);
|
||||
oSpan.m_oFont = *m_pFont;
|
||||
|
||||
oSpan.m_oBrush = *m_pBrush;
|
||||
oSpan.m_oText = m_oTextItem;
|
||||
oSpan.m_dX = x;
|
||||
oSpan.m_dWidthSpan = width;
|
||||
oSpan.m_dBaselineOffset = dCurrentBaselineOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
AVSINLINE void CommandText(BSTR& bsText, BSTR& bsGid, double& x, double& y, double& width, double& height, double& baselineoffset, double& dCurrentBaselineOffset)
|
||||
{
|
||||
if (NULL == bsText)
|
||||
return;
|
||||
|
||||
m_oTextItem.SetText(bsText);
|
||||
|
||||
if (0 == m_oTextItem.GetCurSize())
|
||||
return;
|
||||
|
||||
m_oParagraph.m_rcBounds.top = min(m_oParagraph.m_rcBounds.top, y);
|
||||
m_oParagraph.m_rcBounds.bottom = max(m_oParagraph.m_rcBounds.bottom, y);
|
||||
|
||||
return CommandText(x, y, width, height, baselineoffset, dCurrentBaselineOffset);
|
||||
}
|
||||
};
|
||||
|
||||
class CLogicPageDOCX : public ILogicPage, public CBaseWriter
|
||||
{
|
||||
public:
|
||||
class CLogicShape
|
||||
{
|
||||
public:
|
||||
CDoubleRect m_rcBounds;
|
||||
MediaCore::IAVSUncompressedVideoFrame* m_pFrame;
|
||||
AVSGraphics::IAVSGraphicsRenderer* m_pGraphicsRenderer;
|
||||
|
||||
public:
|
||||
CLogicShape()
|
||||
{
|
||||
m_rcBounds.ClearBounds();
|
||||
|
||||
m_pFrame = NULL;
|
||||
m_pGraphicsRenderer = NULL;
|
||||
}
|
||||
~CLogicShape()
|
||||
{
|
||||
RELEASEINTERFACE(m_pFrame);
|
||||
RELEASEINTERFACE(m_pGraphicsRenderer);
|
||||
}
|
||||
void Clear()
|
||||
{
|
||||
m_rcBounds.ClearBounds();
|
||||
RELEASEINTERFACE(m_pGraphicsRenderer);
|
||||
}
|
||||
void CreateShape(double& dWidth, double& dHeight)
|
||||
{
|
||||
Clear();
|
||||
|
||||
LONG lWidthCur = (LONG)(96.0 * dWidth / 25.4);
|
||||
LONG lHeightCur = (LONG)(96.0 * dHeight / 25.4);
|
||||
|
||||
bool bIsNeedCreate = true;
|
||||
if (NULL != m_pFrame)
|
||||
{
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
m_pFrame->get_Width(&lWidth);
|
||||
m_pFrame->get_Height(&lHeight);
|
||||
|
||||
if ((lWidthCur == lWidth) && (lHeightCur == lHeight))
|
||||
bIsNeedCreate = false;
|
||||
}
|
||||
|
||||
if (bIsNeedCreate)
|
||||
{
|
||||
RELEASEINTERFACE(m_pFrame);
|
||||
|
||||
CoCreateInstance(MediaCore::CLSID_CAVSUncompressedVideoFrame, NULL, CLSCTX_ALL,
|
||||
MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&m_pFrame);
|
||||
|
||||
m_pFrame->put_ColorSpace( ( 1 << 6) | ( 1 << 31) ); // CPS_BGRA | CPS_FLIP
|
||||
m_pFrame->put_Width( lWidthCur );
|
||||
m_pFrame->put_Height( lHeightCur );
|
||||
m_pFrame->put_AspectRatioX( lWidthCur );
|
||||
m_pFrame->put_AspectRatioY( lHeightCur );
|
||||
m_pFrame->put_Interlaced( VARIANT_FALSE );
|
||||
m_pFrame->put_Stride( 0, 4 * lWidthCur );
|
||||
m_pFrame->AllocateBuffer( -1 );
|
||||
}
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
m_pFrame->get_Buffer(&pBuffer);
|
||||
memset(pBuffer, 0xFF, 4 * lWidthCur * lHeightCur);
|
||||
|
||||
CoCreateInstance(AVSGraphics::CLSID_CAVSGraphicsRenderer, NULL, CLSCTX_ALL,
|
||||
AVSGraphics::IID_IAVSGraphicsRenderer, (void**)&m_pGraphicsRenderer);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FontManager
|
||||
VARIANT vtVariant;
|
||||
vtVariant.vt = VT_UNKNOWN;
|
||||
vtVariant.punkVal = NULL;
|
||||
m_pGraphicsRenderer->SetAdditionalParam( L"FontManager", vtVariant );
|
||||
|
||||
m_pGraphicsRenderer->put_Width(dWidth);
|
||||
m_pGraphicsRenderer->put_Height(dHeight);
|
||||
m_pGraphicsRenderer->CreateFromMediaData((IUnknown*)m_pFrame, 0, 0, lWidthCur, lHeightCur );
|
||||
}
|
||||
void GetShape(CBaseWriter* pBaseWriter)
|
||||
{
|
||||
LONG lWidthCur = 0;
|
||||
LONG lHeightCur = 0;
|
||||
m_pFrame->get_Width(&lWidthCur);
|
||||
m_pFrame->get_Height(&lHeightCur);
|
||||
|
||||
LONG lLeft = max(0, min(lWidthCur - 1, (LONG)(m_rcBounds.left * 96.0 / 25.4)));
|
||||
LONG lTop = max(0, min(lHeightCur - 1, (LONG)(m_rcBounds.top * 96.0 / 25.4)));
|
||||
LONG lRight = max(0, min(lWidthCur - 1, (LONG)(m_rcBounds.right * 96.0 / 25.4)));
|
||||
LONG lBottom = max(0, min(lHeightCur - 1, (LONG)(m_rcBounds.bottom * 96.0 / 25.4)));
|
||||
|
||||
if (lRight < lLeft || lBottom < lTop)
|
||||
return;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pShapePicture = NULL;
|
||||
CoCreateInstance(MediaCore::CLSID_CAVSUncompressedVideoFrame, NULL, CLSCTX_ALL,
|
||||
MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pShapePicture);
|
||||
|
||||
LONG lWidthShape = lRight - lLeft + 1;
|
||||
LONG lHeightShape = lBottom - lTop + 1;
|
||||
|
||||
pShapePicture->put_ColorSpace( ( 1 << 6) | ( 1 << 31) ); // CPS_BGRA | CPS_FLIP
|
||||
pShapePicture->put_Width( lWidthShape );
|
||||
pShapePicture->put_Height( lHeightShape );
|
||||
pShapePicture->put_AspectRatioX( lWidthShape );
|
||||
pShapePicture->put_AspectRatioY( lHeightShape );
|
||||
pShapePicture->put_Interlaced( VARIANT_FALSE );
|
||||
pShapePicture->put_Stride( 0, 4 * lWidthShape );
|
||||
pShapePicture->AllocateBuffer( -1 );
|
||||
|
||||
BYTE* pBufferDst = NULL;
|
||||
pShapePicture->get_Buffer(&pBufferDst);
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
m_pFrame->get_Buffer(&pBuffer);
|
||||
|
||||
BYTE* pDstLine = pBufferDst;
|
||||
BYTE* pSrcLine = pBuffer + 4 * (lHeightCur - 1 - lBottom) * lWidthCur + lLeft * 4;
|
||||
|
||||
for (int ind = 0; ind < lHeightShape; ++ind)
|
||||
{
|
||||
memcpy(pDstLine, pSrcLine, 4 * lWidthShape);
|
||||
pDstLine += (4 * lWidthShape);
|
||||
pSrcLine += (4 * lWidthCur);
|
||||
}
|
||||
|
||||
double __x = m_rcBounds.left;
|
||||
double __y = m_rcBounds.top;
|
||||
double __w = m_rcBounds.right - __x;
|
||||
double __h = m_rcBounds.bottom - __y;
|
||||
|
||||
pBaseWriter->WriteShape((IUnknown*)pShapePicture, __x, __y, __w, __h);
|
||||
|
||||
RELEASEINTERFACE(pShapePicture);
|
||||
}
|
||||
|
||||
|
||||
AVSINLINE void MoveTo(double& x, double& y)
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandMoveTo(x, y);
|
||||
m_rcBounds.CheckBounds(x, y);
|
||||
}
|
||||
AVSINLINE void LineTo(double& x, double& y)
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandLineTo(x, y);
|
||||
m_rcBounds.CheckBounds(x, y);
|
||||
}
|
||||
AVSINLINE void CurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandCurveTo(x1, y1, x2, y2, x3, y3);
|
||||
m_rcBounds.CheckBounds(x1, y1);
|
||||
m_rcBounds.CheckBounds(x2, y2);
|
||||
m_rcBounds.CheckBounds(x3, y3);
|
||||
}
|
||||
AVSINLINE void Close()
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandClose();
|
||||
}
|
||||
AVSINLINE void BeginPath()
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandStart();
|
||||
}
|
||||
AVSINLINE void EndPath()
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandEnd();
|
||||
}
|
||||
|
||||
AVSINLINE void WriteText(BSTR& bsText, BSTR& bsGid, double& x, double& y, double& width, double& height, double& baselineoffset,
|
||||
NSStructures::CFont* pFont, NSStructures::CBrush* pBrush)
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
{
|
||||
pFont->SetToRenderer((IAVSRenderer*)m_pGraphicsRenderer);
|
||||
pBrush->SetToRenderer((IAVSRenderer*)m_pGraphicsRenderer);
|
||||
|
||||
if (NULL == bsGid)
|
||||
m_pGraphicsRenderer->CommandDrawText(bsText, x, y, width, height, baselineoffset);
|
||||
else
|
||||
m_pGraphicsRenderer->CommandDrawTextEx(bsText, bsGid, NULL, x, y, width, height, baselineoffset, 0);
|
||||
}
|
||||
|
||||
m_rcBounds.CheckBounds(x, y);
|
||||
m_rcBounds.CheckBounds(x + width, y + height);
|
||||
}
|
||||
AVSINLINE void DrawPath(LONG lPath, NSStructures::CPen* pPen, NSStructures::CBrush* pBrush)
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
{
|
||||
pPen->SetToRenderer((IAVSRenderer*)m_pGraphicsRenderer);
|
||||
pBrush->SetToRenderer((IAVSRenderer*)m_pGraphicsRenderer);
|
||||
m_pGraphicsRenderer->DrawPath(lPath);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
CLogicShape m_oCurrentShape;
|
||||
LONG m_lShapeTop;
|
||||
|
||||
CTextSmart m_oText;
|
||||
bool m_bIsPar;
|
||||
double m_dCurrentBaselineOffset;
|
||||
|
||||
double m_dLastTop;
|
||||
|
||||
public:
|
||||
CLogicPageDOCX() : ILogicPage()
|
||||
{
|
||||
m_lShapeTop = 0;
|
||||
m_bIsPar = false;
|
||||
}
|
||||
~CLogicPageDOCX()
|
||||
{
|
||||
}
|
||||
public:
|
||||
virtual void ConvertToEbookPage(NSEBook::CFormat& oFormat)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GetPositionY()
|
||||
|
||||
CAtlList<ILogicItem*> arraySort;
|
||||
|
||||
while (0 != m_arItems.GetCount())
|
||||
{
|
||||
POSITION pos = m_arItems.GetHeadPosition();
|
||||
POSITION posNeed = pos;
|
||||
|
||||
ILogicItem* pItem = m_arItems.GetNext(pos);
|
||||
double dMin = pItem->GetPositionY();
|
||||
while (NULL != pos)
|
||||
{
|
||||
POSITION posOld = pos;
|
||||
pItem = m_arItems.GetNext(pos);
|
||||
|
||||
double dMem = pItem->GetPositionY();
|
||||
if (dMem < dMin)
|
||||
{
|
||||
dMin = dMem;
|
||||
posNeed = posOld;
|
||||
}
|
||||
}
|
||||
|
||||
ILogicItem* pNeed = m_arItems.GetAt(posNeed);
|
||||
m_arItems.RemoveAt(posNeed);
|
||||
arraySort.AddTail(pNeed);
|
||||
}
|
||||
m_arItems.RemoveAll();
|
||||
m_arItems.AddTailList(&arraySort);
|
||||
arraySort.RemoveAll();
|
||||
|
||||
CEbookParagraph* pLogicParagraph = NULL;
|
||||
|
||||
if (0 != oFormat.m_listSections.GetCount())
|
||||
{
|
||||
CSection& oSectionLast = oFormat.m_listSections.GetTail();
|
||||
IEbookItem* pItem = oSectionLast.m_arItems.GetTail();
|
||||
|
||||
if (NULL != pItem)
|
||||
{
|
||||
if (IEbookItem::ebitParagraph == pItem->m_eType)
|
||||
{
|
||||
pLogicParagraph = (CEbookParagraph*)pItem;
|
||||
|
||||
if (pLogicParagraph->m_bIsComplete)
|
||||
pLogicParagraph = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
POSITION pos = m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CSection* pSection = NULL;
|
||||
bool bIsFirstSection = true;
|
||||
if (0 == oFormat.m_listSections.GetCount())
|
||||
{
|
||||
oFormat.m_listSections.AddTail();
|
||||
pSection = &oFormat.m_listSections.GetTail();
|
||||
}
|
||||
else
|
||||
{
|
||||
pSection = &oFormat.m_listSections.GetTail();
|
||||
bIsFirstSection = false;
|
||||
}
|
||||
|
||||
ILogicItem* pItem = m_arItems.GetNext(pos);
|
||||
|
||||
if (ILogicItem::elitTextParagraph == pItem->m_eType)
|
||||
{
|
||||
CLogicParagraph* paragraph = dynamic_cast<CLogicParagraph*>(pItem);
|
||||
|
||||
if (paragraph->m_oParagraph.m_lStyle == 1 && !bIsFirstSection)
|
||||
{
|
||||
// <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> title. <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> - <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (1 < pSection->m_arItems.GetCount())
|
||||
{
|
||||
oFormat.m_listSections.AddTail();
|
||||
pSection = &oFormat.m_listSections.GetTail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case ILogicItem::elitTextParagraph:
|
||||
{
|
||||
CLogicParagraph* pCurrentPar = (CLogicParagraph*)pItem;
|
||||
if (NULL != pLogicParagraph)
|
||||
{
|
||||
// <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!!!
|
||||
pLogicParagraph->m_arLines.AddTailList(&pCurrentPar->m_oParagraph.m_arLines);
|
||||
pLogicParagraph->m_bIsComplete = pCurrentPar->m_oParagraph.m_bIsComplete;
|
||||
|
||||
pLogicParagraph->m_bIsPageBreakAfter = pItem->m_bIsPageBreakAfter;
|
||||
|
||||
pLogicParagraph = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
CEbookParagraph* pParagraph = new CEbookParagraph(pCurrentPar->m_oParagraph);
|
||||
pParagraph->m_bIsPageBreakAfter = pItem->m_bIsPageBreakAfter;
|
||||
pSection->m_arItems.AddTail(pParagraph);
|
||||
|
||||
CheckWatermark(oFormat);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ILogicItem::elitTable:
|
||||
{
|
||||
CEbookTable* pTable = new CEbookTable();
|
||||
pTable->m_strTableXml = ((CLogicTable*)pItem)->m_strTableXml;
|
||||
pSection->m_arItems.AddTail(pTable);
|
||||
|
||||
pTable->m_bIsPageBreakAfter = pItem->m_bIsPageBreakAfter;
|
||||
|
||||
CheckWatermark(oFormat);
|
||||
break;
|
||||
}
|
||||
case ILogicItem::elitGraphic:
|
||||
{
|
||||
CLogicImage* pLogicImage = ((CLogicImage*)pItem);
|
||||
|
||||
CEbookGraphicObject* pImage = new CEbookGraphicObject();
|
||||
pImage->m_oInfo = pLogicImage->m_oImageInfo;
|
||||
pImage->m_rcBounds = pItem->m_rcBounds;
|
||||
pSection->m_arItems.AddTail(pImage);
|
||||
|
||||
pImage->m_bIsPageBreakAfter = pItem->m_bIsPageBreakAfter;
|
||||
|
||||
CheckWatermark(oFormat);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void MoveTo(double& x, double& y)
|
||||
{
|
||||
m_oCurrentShape.MoveTo(x, y);
|
||||
}
|
||||
virtual void LineTo(double& x, double& y)
|
||||
{
|
||||
m_oCurrentShape.LineTo(x, y);
|
||||
}
|
||||
virtual void CurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
|
||||
{
|
||||
m_oCurrentShape.CurveTo(x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
virtual void Close()
|
||||
{
|
||||
m_oCurrentShape.Close();
|
||||
}
|
||||
virtual void BeginPath()
|
||||
{
|
||||
m_oCurrentShape.BeginPath();
|
||||
}
|
||||
virtual void EndPath()
|
||||
{
|
||||
m_oCurrentShape.EndPath();
|
||||
}
|
||||
|
||||
AVSINLINE void BeginParagraph()
|
||||
{
|
||||
if (m_bIsPar)
|
||||
return;
|
||||
|
||||
m_bIsPar = true;
|
||||
m_oText.m_oParagraph.m_rcBounds.top = 100000;
|
||||
m_oText.m_oParagraph.m_rcBounds.bottom = -100000;
|
||||
}
|
||||
AVSINLINE void EndParagraph()
|
||||
{
|
||||
if (100000 == m_oText.m_oParagraph.m_rcBounds.top)
|
||||
{
|
||||
if (100000 != m_dLastTop)
|
||||
{
|
||||
++m_dLastTop;
|
||||
m_oText.m_oParagraph.m_rcBounds.top = m_dLastTop;
|
||||
}
|
||||
}
|
||||
|
||||
if (100000 != m_oText.m_oParagraph.m_rcBounds.top)
|
||||
{
|
||||
CLogicParagraph* pPar = new CLogicParagraph(m_oText.m_oParagraph);
|
||||
pPar->m_rcBounds = m_oText.m_oParagraph.m_rcBounds;
|
||||
m_arItems.AddTail(pPar);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dLastTop = m_oText.m_oParagraph.m_rcBounds.top;
|
||||
}
|
||||
|
||||
m_oText.m_oParagraph.m_bIsComplete = true;
|
||||
m_oText.m_oParagraph.Clear();
|
||||
m_bIsPar = false;
|
||||
}
|
||||
AVSINLINE void BeginLine()
|
||||
{
|
||||
m_dCurrentBaselineOffset = 0;
|
||||
m_oText.m_oParagraph.m_arLines.AddTail();
|
||||
}
|
||||
AVSINLINE void EndLine()
|
||||
{
|
||||
}
|
||||
AVSINLINE void SetBaselineOffset(double dOffset)
|
||||
{
|
||||
m_dCurrentBaselineOffset = dOffset;
|
||||
}
|
||||
AVSINLINE void SetParagraphStyle(LONG lStyle)
|
||||
{
|
||||
m_oText.m_oParagraph.m_lStyle = lStyle;
|
||||
}
|
||||
AVSINLINE void SetParTextAlign(LONG lAlign)
|
||||
{
|
||||
m_oText.m_oParagraph.m_lTextAlign = lAlign;
|
||||
}
|
||||
AVSINLINE void SetParagraphNumLevel(LONG lLevel)
|
||||
{
|
||||
m_oText.m_oParagraph.m_lNumberingLevel = lLevel;
|
||||
}
|
||||
|
||||
virtual void WriteText(BSTR& bsText, BSTR& bsGid, double& x, double& y, double& width, double& height, double& baselineoffset)
|
||||
{
|
||||
if (0 != m_lShapeTop)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
m_oCurrentShape.WriteText(bsText, bsGid, x, y, width, height, baselineoffset, m_pFont, m_pBrush);
|
||||
return;
|
||||
}
|
||||
|
||||
m_oText.CommandText(bsText, bsGid, x, y, width, height, baselineoffset, m_dCurrentBaselineOffset);
|
||||
m_dCurrentBaselineOffset = 0.0;
|
||||
}
|
||||
|
||||
virtual void WriteTable(NSEBook::ILogicItem* pItem)
|
||||
{
|
||||
m_arItems.AddTail(pItem);
|
||||
}
|
||||
|
||||
AVSINLINE void WriteTableTop(double dTop)
|
||||
{
|
||||
ILogicItem* pItem = m_arItems.GetTail();
|
||||
if (NULL != pItem)
|
||||
{
|
||||
if (ILogicItem::elitTable == pItem->m_eType)
|
||||
pItem->m_rcBounds.top = dTop;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void BeginShape()
|
||||
{
|
||||
if (0 == m_lShapeTop)
|
||||
m_oCurrentShape.CreateShape(m_dWidth, m_dHeight);
|
||||
++m_lShapeTop;
|
||||
}
|
||||
virtual void EndShape()
|
||||
{
|
||||
--m_lShapeTop;
|
||||
if (0 == m_lShapeTop)
|
||||
{
|
||||
// <20><><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
m_oCurrentShape.GetShape((CBaseWriter*)this);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void DrawPath(LONG lType)
|
||||
{
|
||||
m_oCurrentShape.DrawPath(lType, m_pPen, m_pBrush);
|
||||
}
|
||||
virtual void Clear()
|
||||
{
|
||||
POSITION pos = m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
ILogicItem* pItem = m_arItems.GetNext(pos);
|
||||
RELEASEOBJECT(pItem);
|
||||
}
|
||||
m_arItems.RemoveAll();
|
||||
|
||||
m_oCurrentShape.Clear();
|
||||
m_lShapeTop = 0;
|
||||
}
|
||||
|
||||
virtual void BeginPage()
|
||||
{
|
||||
m_bIsPar = false;
|
||||
m_lShapeTop = 0;
|
||||
m_dCurrentBaselineOffset = 0;
|
||||
m_dLastTop = 100000;
|
||||
}
|
||||
virtual void EndPage()
|
||||
{
|
||||
if (m_bIsPar)
|
||||
{
|
||||
m_oText.m_oParagraph.m_bIsComplete = false;
|
||||
EndParagraph();
|
||||
}
|
||||
|
||||
m_bIsDumpWatermark = true;
|
||||
}
|
||||
virtual void CloseFile(NSEBook::CFormat& oFormat)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void WriteImage(IUnknown* punkImage, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
if (!m_bIsPar)
|
||||
{
|
||||
CLogicImage* pImage = new CLogicImage();
|
||||
pImage->m_oImageInfo = m_pImageManager->WriteImage(punkImage, x, y, width, height);
|
||||
pImage->m_rcBounds.left = x;
|
||||
pImage->m_rcBounds.top = y;
|
||||
pImage->m_rcBounds.right = x + width;
|
||||
pImage->m_rcBounds.bottom = y + height;
|
||||
m_arItems.AddTail(pImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
CEbookParagraph::CSpan oSpan;
|
||||
oSpan.m_oImageInfo = m_pImageManager->WriteImage(punkImage, x, y, width, height);
|
||||
oSpan.m_dImageWidth = width;
|
||||
oSpan.m_dImageHeight = height;
|
||||
|
||||
oSpan.m_dX = x;
|
||||
oSpan.m_dWidthSpan = width;
|
||||
|
||||
m_oText.m_oParagraph.m_rcBounds.top = min(m_oText.m_oParagraph.m_rcBounds.top, y);
|
||||
m_oText.m_oParagraph.m_rcBounds.bottom = max(m_oText.m_oParagraph.m_rcBounds.bottom, y);
|
||||
|
||||
CEbookParagraph::CLine& oCurLine = m_oText.GetCurrentLine();
|
||||
|
||||
if (0 == oCurLine.m_listSpans.GetCount())
|
||||
{
|
||||
oCurLine.m_listSpans.AddTail(oSpan);
|
||||
}
|
||||
else
|
||||
{
|
||||
CEbookParagraph::CSpan& oTail = oCurLine.m_listSpans.GetTail();
|
||||
if (-1 == oTail.m_oImageInfo.m_lID)
|
||||
{
|
||||
if (c_dSpaceW < abs(oTail.m_dX + oTail.m_dWidthSpan - x))
|
||||
{
|
||||
oTail.m_oText.AddSpace();
|
||||
}
|
||||
}
|
||||
oCurLine.m_listSpans.AddTail(oSpan);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void WriteShape(IUnknown* punkImage, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
WriteImage(punkImage, x, y, width, height);
|
||||
}
|
||||
virtual void WriteImage(CString strFilePath, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
if (!m_bIsPar)
|
||||
{
|
||||
CLogicImage* pImage = new CLogicImage();
|
||||
pImage->m_oImageInfo = m_pImageManager->WriteImage(strFilePath, x, y, width, height);
|
||||
pImage->m_rcBounds.left = x;
|
||||
pImage->m_rcBounds.top = y;
|
||||
pImage->m_rcBounds.right = x + width;
|
||||
pImage->m_rcBounds.bottom = y + height;
|
||||
m_arItems.AddTail(pImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
CEbookParagraph::CSpan oSpan;
|
||||
oSpan.m_oImageInfo = m_pImageManager->WriteImage(strFilePath, x, y, width, height);
|
||||
oSpan.m_dImageWidth = width;
|
||||
oSpan.m_dImageHeight = height;
|
||||
|
||||
oSpan.m_dX = x;
|
||||
oSpan.m_dWidthSpan = width;
|
||||
|
||||
CEbookParagraph::CLine& oCurLine = m_oText.GetCurrentLine();
|
||||
|
||||
if (0 == oCurLine.m_listSpans.GetCount())
|
||||
{
|
||||
oCurLine.m_listSpans.AddTail(oSpan);
|
||||
}
|
||||
else
|
||||
{
|
||||
CEbookParagraph::CSpan& oTail = oCurLine.m_listSpans.GetTail();
|
||||
if (-1 == oTail.m_oImageInfo.m_lID)
|
||||
{
|
||||
if (c_dSpaceW < abs(oTail.m_dX + oTail.m_dWidthSpan - x))
|
||||
{
|
||||
oTail.m_oText.AddSpace();
|
||||
}
|
||||
}
|
||||
oCurLine.m_listSpans.AddTail(oSpan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void InitProp()
|
||||
{
|
||||
m_oText.m_pFontsDst = &m_oFontsGen;
|
||||
m_oText.m_pFontManager = &m_oFontManager;
|
||||
m_oText.SetParams(m_pPen, m_pBrush, m_pFont, m_pTransform);
|
||||
m_oFontsGen.m_lCountFonts = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
BIN
AVSEBOOKWriter/Logic/LogicPagePDF.h
Normal file
BIN
AVSEBOOKWriter/Logic/LogicPagePDF.h
Normal file
Binary file not shown.
38
AVSEBOOKWriter/Logic/Text.h
Normal file
38
AVSEBOOKWriter/Logic/Text.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include "../Common/FontManager.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
using namespace NSCommon;
|
||||
|
||||
class ILogicItem
|
||||
{
|
||||
public:
|
||||
enum ELogicItemType
|
||||
{
|
||||
elitTextLine = 0,
|
||||
elitTable = 1,
|
||||
elitGraphic = 2,
|
||||
elitTextParagraph = 3
|
||||
};
|
||||
|
||||
ELogicItemType m_eType;
|
||||
CDoubleRect m_rcBounds;
|
||||
bool m_bIsPageBreakAfter;
|
||||
|
||||
public:
|
||||
ILogicItem()
|
||||
{
|
||||
m_eType = elitTextLine;
|
||||
m_bIsPageBreakAfter = false;
|
||||
}
|
||||
virtual ~ILogicItem()
|
||||
{
|
||||
}
|
||||
|
||||
virtual double GetPositionY() = 0;
|
||||
virtual double GetPositionX() = 0;
|
||||
};
|
||||
|
||||
const long g_lNewNoJustifySpace = 5;
|
||||
}
|
||||
250
AVSEBOOKWriter/MOBIFormat/MobiFile.h
Normal file
250
AVSEBOOKWriter/MOBIFormat/MobiFile.h
Normal file
@ -0,0 +1,250 @@
|
||||
#pragma once
|
||||
#include "MobiReader.h"
|
||||
#include "..\..\Common\OfficeFileTemplate.h"
|
||||
#include "..\..\AVSOfficeFile\OfficeEventsTemplate.h"
|
||||
#include "..\..\Common\OfficeFileFormats.h"
|
||||
#include "..\..\Common\OfficeFileErrorDescription.h"
|
||||
|
||||
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
|
||||
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
|
||||
#endif
|
||||
|
||||
template <class T, class Reciever>
|
||||
class COfficeHtmlEvent : public COfficeEventTemplate<T,Reciever>
|
||||
{
|
||||
public:
|
||||
COfficeHtmlEvent(Reciever *pReciever):COfficeEventTemplate(pReciever)
|
||||
{
|
||||
m_cnt = 0;
|
||||
m_dwAdvise = 0;
|
||||
};
|
||||
HRESULT OnProgress( LONG nID, LONG nPercent )
|
||||
{
|
||||
m_pReciever->OnProgress( nID, nPercent );
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT OnProgressEx( LONG nID, LONG nPercent, SHORT* Cancel )
|
||||
{
|
||||
m_pReciever->OnProgressEx( nID, nPercent, Cancel );
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
|
||||
VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
|
||||
{
|
||||
//CTemporaryCS oCS(&m_csThread);
|
||||
HRESULT hr;
|
||||
VARIANTARG varg0;
|
||||
VARIANTARG varg1;
|
||||
VARIANTARG varg2;
|
||||
switch(dispIdMember) {
|
||||
case 1:
|
||||
VariantInit(&varg0);
|
||||
VariantInit(&varg1);
|
||||
hr = DispGetParam(pDispParams,0,VT_I4,&varg0,puArgErr);
|
||||
hr = DispGetParam(pDispParams,1,VT_I4,&varg1,puArgErr);
|
||||
OnProgress( varg0.lVal, varg1.lVal );
|
||||
return(S_OK);
|
||||
break;
|
||||
case 2:
|
||||
VariantInit(&varg0);
|
||||
VariantInit(&varg1);
|
||||
VariantInit(&varg2);
|
||||
hr = DispGetParam(pDispParams,0,VT_I4,&varg0,puArgErr);
|
||||
hr = DispGetParam(pDispParams,1,VT_I4,&varg1,puArgErr);
|
||||
hr = DispGetParam(pDispParams,2,VT_I2,&varg2,puArgErr);
|
||||
OnProgressEx( varg0.lVal, varg1.lVal, &varg2.iVal );
|
||||
if (pDispParams->rgvarg[0].vt & VT_BYREF) // implemented now for last VT_I2 arg only
|
||||
{
|
||||
SHORT* p = (SHORT*)pDispParams->rgvarg[0].byref;
|
||||
if (p) *p = varg2.iVal;
|
||||
}
|
||||
return(S_OK);
|
||||
break;
|
||||
default:
|
||||
return(E_NOTIMPL);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// IOfficeMobiFile
|
||||
[
|
||||
object,
|
||||
uuid("A603595B-F537-4dbd-A616-4DFFF11613F0"),
|
||||
dual, helpstring("IOfficeMobiFile Interface"),
|
||||
pointer_default(unique)
|
||||
]
|
||||
__interface IOfficeMobiFile : IAVSOfficeFileTemplate
|
||||
{
|
||||
[id(10)] HRESULT SetAdditionalParam([in] BSTR ParamName, [in] VARIANT ParamValue);
|
||||
[id(20)] HRESULT GetAdditionalParam([in] BSTR ParamName, [out, retval] VARIANT* ParamValue);
|
||||
};
|
||||
|
||||
// COfficeMobiFile
|
||||
[
|
||||
coclass,
|
||||
default(IOfficeMobiFile),
|
||||
threading(apartment),
|
||||
event_source(com),
|
||||
vi_progid("Ebook.Mobi"),
|
||||
progid("Ebook.Mobi.1"),
|
||||
version(1.0),
|
||||
uuid("CB6B5C2C-9F3B-47d8-A184-187919722F88"),
|
||||
helpstring("COfficeMobiFile Class")
|
||||
]
|
||||
class ATL_NO_VTABLE COfficeMobiFile : public IOfficeMobiFile
|
||||
{
|
||||
public:
|
||||
COfficeMobiFile()
|
||||
{
|
||||
}
|
||||
__event __interface _IAVSOfficeFileTemplateEvents;
|
||||
__event __interface _IAVSOfficeFileTemplateEvents2;
|
||||
DECLARE_PROTECT_FINAL_CONSTRUCT()
|
||||
|
||||
HRESULT FinalConstruct()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void FinalRelease()
|
||||
{
|
||||
}
|
||||
public:
|
||||
STDMETHOD(LoadFromFile)( BSTR bstrSrcFileName, BSTR bstrDstPath, BSTR bstrXMLOptions)
|
||||
{
|
||||
CString strSrcFileName = (CString)bstrSrcFileName;
|
||||
if (!IsMobiFile(strSrcFileName))
|
||||
return S_FALSE;
|
||||
|
||||
NSMobi::CMobiReader oReader;
|
||||
oReader.m_oTempManager.m_strTempDirectory = _T("");
|
||||
oReader.m_bIsCorrectHtml = true;
|
||||
|
||||
m_strMetadata = _T("");
|
||||
bool bIsDRM = false;
|
||||
bool bIsMobi = oReader.OpenFile(strSrcFileName, bIsDRM);
|
||||
m_strMetadata = oReader.m_strMeta;
|
||||
|
||||
if (bIsDRM)
|
||||
{
|
||||
oReader.CloseFile();
|
||||
return AVS_ERROR_DRM;
|
||||
}
|
||||
|
||||
CString strHtmlFile = oReader.m_oTempManager.m_strTempDirectory + _T("\\index.html");
|
||||
CFile oFile;
|
||||
oFile.OpenFile(strHtmlFile);
|
||||
if (0 == oFile.GetFileSize())
|
||||
{
|
||||
oFile.CloseFile();
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
HRESULT hrRes = S_FALSE;
|
||||
if (bIsMobi)
|
||||
{
|
||||
OfficeHtmlFile::IHtmlFilePtr piHtmlFile;
|
||||
piHtmlFile.CreateInstance(__uuidof(OfficeHtmlFile::CHtmlFile));
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COfficeHtmlEvent< OfficeHtmlFile::_IAVSOfficeFileTemplateEvents, COfficeMobiFile >* oHtmlEvents = new COfficeHtmlEvent< OfficeHtmlFile::_IAVSOfficeFileTemplateEvents, COfficeMobiFile >( this );
|
||||
oHtmlEvents->AddRef();
|
||||
oHtmlEvents->Advise( piHtmlFile );
|
||||
COfficeHtmlEvent< OfficeHtmlFile::_IAVSOfficeFileTemplateEvents2, COfficeMobiFile >* oHtmlEvents2 = new COfficeHtmlEvent< OfficeHtmlFile::_IAVSOfficeFileTemplateEvents2, COfficeMobiFile >( this );
|
||||
oHtmlEvents2->AddRef();
|
||||
oHtmlEvents2->Advise( piHtmlFile );
|
||||
|
||||
BSTR bsSrc = strHtmlFile.AllocSysString();
|
||||
CString sOptions;
|
||||
sOptions.AppendFormat( _T("<Options><FileType>%d</FileType></Options>"), AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML );
|
||||
BSTR bstrOptions = sOptions.AllocSysString();
|
||||
hrRes = piHtmlFile->LoadFromFile(bsSrc, bstrDstPath, bstrOptions);
|
||||
SysFreeString(bsSrc);
|
||||
SysFreeString(bstrOptions);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
oHtmlEvents->UnAdvise( piHtmlFile );
|
||||
RELEASEINTERFACE( oHtmlEvents );
|
||||
oHtmlEvents2->UnAdvise( piHtmlFile );
|
||||
RELEASEINTERFACE( oHtmlEvents2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
OfficeTxtFile::ITxtFilePtr piHtmlFile;
|
||||
piHtmlFile.CreateInstance(__uuidof(OfficeTxtFile::CTxtFile));
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COfficeHtmlEvent< OfficeTxtFile::_IAVSOfficeFileTemplateEvents, COfficeMobiFile >* oHtmlEvents = new COfficeHtmlEvent< OfficeTxtFile::_IAVSOfficeFileTemplateEvents, COfficeMobiFile >( this );
|
||||
oHtmlEvents->AddRef();
|
||||
oHtmlEvents->Advise( piHtmlFile );
|
||||
COfficeHtmlEvent< OfficeTxtFile::_IAVSOfficeFileTemplateEvents2, COfficeMobiFile >* oHtmlEvents2 = new COfficeHtmlEvent< OfficeTxtFile::_IAVSOfficeFileTemplateEvents2, COfficeMobiFile >( this );
|
||||
oHtmlEvents2->AddRef();
|
||||
oHtmlEvents2->Advise( piHtmlFile );
|
||||
|
||||
strHtmlFile.Replace(_T("\\\\"), _T("\\"));
|
||||
BSTR bsSrc = strHtmlFile.AllocSysString();
|
||||
CString sOptions;
|
||||
sOptions.AppendFormat( _T("<Options><FileType>%d</FileType></Options>"), AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT );
|
||||
BSTR bstrOptions = sOptions.AllocSysString();
|
||||
hrRes = piHtmlFile->LoadFromFile(bsSrc, bstrDstPath, bstrOptions);
|
||||
SysFreeString(bsSrc);
|
||||
SysFreeString(bstrOptions);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
oHtmlEvents->UnAdvise( piHtmlFile );
|
||||
RELEASEINTERFACE( oHtmlEvents );
|
||||
oHtmlEvents2->UnAdvise( piHtmlFile );
|
||||
RELEASEINTERFACE( oHtmlEvents2 );
|
||||
}
|
||||
|
||||
oReader.CloseFile();
|
||||
|
||||
return hrRes;
|
||||
}
|
||||
STDMETHOD(SaveToFile)( BSTR bstrDstFileName, BSTR bstrSrcPath, BSTR bstrXMLOptions)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(SetAdditionalParam)( BSTR ParamName, VARIANT ParamValue)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(GetAdditionalParam)( BSTR ParamName, VARIANT* ParamValue)
|
||||
{
|
||||
CString sParamName = ParamName;
|
||||
if (_T("Metadata") == sParamName)
|
||||
{
|
||||
ParamValue->vt = VT_BSTR;
|
||||
ParamValue->bstrVal = m_strMetadata.AllocSysString();
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
BOOL IsMobiFile(CString sFilename)
|
||||
{
|
||||
CFile oFile;
|
||||
oFile.OpenFile(sFilename);
|
||||
if (70 > oFile.GetFileSize())
|
||||
return FALSE;
|
||||
|
||||
oFile.SetPosition(0);
|
||||
oFile.SkipBytes(60);
|
||||
|
||||
NSMobi::CStream oStream;
|
||||
oStream.CreateFromBuffer(10);
|
||||
oFile.ReadFile(oStream.GetBuffer(), 10);
|
||||
CString strId = oStream.ReadStringA(8);
|
||||
|
||||
BOOL bIsMobi = FALSE;
|
||||
if ((strId == _T("BOOKMOBI")) || (strId == _T("TEXtREAd")))
|
||||
bIsMobi = TRUE;
|
||||
|
||||
oFile.CloseFile();
|
||||
return bIsMobi;
|
||||
}
|
||||
private:
|
||||
|
||||
CString m_strMetadata;
|
||||
};
|
||||
1597
AVSEBOOKWriter/MOBIFormat/MobiReader.h
Normal file
1597
AVSEBOOKWriter/MOBIFormat/MobiReader.h
Normal file
File diff suppressed because it is too large
Load Diff
634
AVSEBOOKWriter/TableDetector.h
Normal file
634
AVSEBOOKWriter/TableDetector.h
Normal file
@ -0,0 +1,634 @@
|
||||
namespace NSEBook
|
||||
{
|
||||
class CTable
|
||||
{
|
||||
private:
|
||||
double m_x;
|
||||
double m_y;
|
||||
double m_width;
|
||||
double m_height;
|
||||
|
||||
ATL::CSimpleArray<double> m_columns;
|
||||
ATL::CSimpleArray<double> m_rows;
|
||||
|
||||
public:
|
||||
CTable()
|
||||
{
|
||||
m_x = 0;
|
||||
m_y = 0;
|
||||
m_width = 0;
|
||||
m_height = 0;
|
||||
}
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
m_x = 0;
|
||||
m_y = 0;
|
||||
m_width = 0;
|
||||
m_height = 0;
|
||||
|
||||
m_columns.RemoveAll();
|
||||
m_rows.RemoveAll();
|
||||
}
|
||||
|
||||
void SetStartPos( double x, double y )
|
||||
{
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
}
|
||||
void AddRow( double height )
|
||||
{
|
||||
if( height < DBL_EPSILON )
|
||||
return;
|
||||
|
||||
if( m_rows.Add( m_height ) )
|
||||
{
|
||||
m_height += height;
|
||||
}
|
||||
}
|
||||
|
||||
void AddColumn( double width )
|
||||
{
|
||||
if( width < DBL_EPSILON )
|
||||
return;
|
||||
|
||||
if( m_columns.Add( m_width ) )
|
||||
{
|
||||
m_width += width;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool IsEmpty() const
|
||||
{
|
||||
return (!m_width || !m_height);
|
||||
}
|
||||
|
||||
double GetX() const
|
||||
{
|
||||
return m_x;
|
||||
}
|
||||
|
||||
double GetY() const
|
||||
{
|
||||
return m_y;
|
||||
}
|
||||
|
||||
double GetWidth() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
double GetHeight() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
int GetCountRows() const
|
||||
{
|
||||
m_rows.GetSize();
|
||||
}
|
||||
|
||||
int GetCountColumns() const
|
||||
{
|
||||
m_columns.GetSize();
|
||||
}
|
||||
|
||||
double GetRowPosition( int id ) const
|
||||
{
|
||||
return m_rows[id];
|
||||
}
|
||||
|
||||
double GetColumnPosition( int id ) const
|
||||
{
|
||||
return m_columns[id];
|
||||
}
|
||||
|
||||
double GetRowSize( int id ) const
|
||||
{
|
||||
return ((id < m_rows.GetSize() - 1) ? m_rows[id + 1] : m_height) - m_rows[id];
|
||||
}
|
||||
|
||||
double GetColumnSize( int id ) const
|
||||
{
|
||||
return ((id < m_columns.GetSize() - 1) ? m_columns[id + 1] : m_height) - m_columns[id];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class CTableDetector
|
||||
{
|
||||
protected:
|
||||
class TGroup;
|
||||
|
||||
class TBlock
|
||||
{
|
||||
double m_x1, m_y1, m_x2, m_y2;
|
||||
TGroup* m_group;
|
||||
|
||||
public:
|
||||
|
||||
TBlock()
|
||||
{
|
||||
m_x1 = 0;
|
||||
m_y1 = 0;
|
||||
m_x2 = 0;
|
||||
m_y2 = 0;
|
||||
m_group = NULL;
|
||||
}
|
||||
|
||||
TBlock( double _x1, double _y1, double _x2, double _y2 )
|
||||
{
|
||||
Set( _x1, _y1, _x2, _y2 );
|
||||
}
|
||||
|
||||
void Set( double _x1, double _y1, double _x2, double _y2 )
|
||||
{
|
||||
if( _x1 < _x2 )
|
||||
{
|
||||
m_x1 = _x1;
|
||||
m_x2 = _x2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_x1 = _x2;
|
||||
m_x2 = _x1;
|
||||
}
|
||||
|
||||
if( _y1 < _y2 )
|
||||
{
|
||||
m_y1 = _y1;
|
||||
m_y2 = _y2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_y1 = _y2;
|
||||
m_y2 = _y1;
|
||||
}
|
||||
|
||||
m_group = NULL;
|
||||
}
|
||||
|
||||
double GetX() const
|
||||
{
|
||||
return m_x1;
|
||||
}
|
||||
|
||||
double GetY() const
|
||||
{
|
||||
return m_y1;
|
||||
}
|
||||
|
||||
double GetWidth() const
|
||||
{
|
||||
return m_x2 - m_x1;
|
||||
}
|
||||
|
||||
double GetHeight() const
|
||||
{
|
||||
return m_y2 - m_y1;
|
||||
}
|
||||
|
||||
double GetCenterX() const
|
||||
{
|
||||
return (m_x1 + m_x2) * 0.5;
|
||||
}
|
||||
|
||||
double GetCenterY() const
|
||||
{
|
||||
return (m_y1 + m_y2) * 0.5;
|
||||
}
|
||||
|
||||
double GetX2() const
|
||||
{
|
||||
return m_x2;
|
||||
}
|
||||
double GetY2() const
|
||||
{
|
||||
return m_y2;
|
||||
}
|
||||
bool Intersect( const TBlock& out ) const
|
||||
{
|
||||
double l = max(m_x1, out.m_x1);
|
||||
double t = max(m_y1, out.m_y1);
|
||||
double r = min(m_x2, out.m_x2);
|
||||
double b = min(m_y2, out.m_y2);
|
||||
|
||||
if( l > r || t > b )
|
||||
return false;
|
||||
|
||||
if( l <= m_x1 && t <= m_y1 && r >= m_x2 && b >= m_y2 )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Intersect( const TBlock& out, TBlock& result ) const
|
||||
{
|
||||
double l = max(m_x1, out.m_x1);
|
||||
double t = max(m_y1, out.m_y1);
|
||||
double r = min(m_x2, out.m_x2);
|
||||
double b = min(m_y2, out.m_y2);
|
||||
|
||||
if( l > r || t > b )
|
||||
return false;
|
||||
|
||||
result.m_x1 = l;
|
||||
result.m_y1 = t;
|
||||
result.m_x2 = r;
|
||||
result.m_y2 = b;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetGroup( TGroup* pGroup )
|
||||
{
|
||||
m_group = pGroup;
|
||||
}
|
||||
|
||||
TGroup* GetGroup() const
|
||||
{
|
||||
return m_group;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class TCrossPoint
|
||||
{
|
||||
public:
|
||||
double m_x, m_y;
|
||||
TBlock* m_pHorBlock;
|
||||
TBlock* m_pVerBlock;
|
||||
|
||||
public:
|
||||
TCrossPoint()
|
||||
{
|
||||
m_x = 0;
|
||||
m_y = 0;
|
||||
m_pHorBlock = NULL;
|
||||
m_pVerBlock = NULL;
|
||||
}
|
||||
|
||||
TCrossPoint( double x, double y, TBlock* pHorBlock, TBlock* pVerBlock )
|
||||
{
|
||||
Set( x, y, pHorBlock, pVerBlock );
|
||||
}
|
||||
|
||||
void Set( double x, double y, TBlock* pHorBlock, TBlock* pVerBlock )
|
||||
{
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
m_pHorBlock = pHorBlock;
|
||||
m_pVerBlock = pVerBlock;
|
||||
}
|
||||
};
|
||||
|
||||
class TGroup
|
||||
{
|
||||
public:
|
||||
CAtlArray<TBlock*> m_blocks;
|
||||
CAtlArray<TCrossPoint*> m_points;
|
||||
};
|
||||
|
||||
|
||||
CAtlList<TBlock> m_HorBlocks;
|
||||
CAtlList<TBlock> m_VerBlocks;
|
||||
CAtlList<CTable> m_Tables;
|
||||
|
||||
POSITION m_pCurTable;
|
||||
|
||||
public:
|
||||
CTableDetector()
|
||||
{
|
||||
m_pCurTable = NULL;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
m_HorBlocks.RemoveAll();
|
||||
m_VerBlocks.RemoveAll();
|
||||
m_Tables.RemoveAll();
|
||||
|
||||
m_pCurTable = NULL;
|
||||
}
|
||||
|
||||
void AddBlock( const double points[4][2] )
|
||||
{
|
||||
if( points[0][0] != points[1][0] )
|
||||
{
|
||||
if( abs(points[0][1] - points[1][1]) > FLT_EPSILON ||
|
||||
abs(points[1][0] - points[2][0]) > FLT_EPSILON ||
|
||||
abs(points[2][1] - points[3][1]) > FLT_EPSILON ||
|
||||
abs(points[3][0] - points[0][0]) > FLT_EPSILON )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( abs(points[0][0] - points[1][0]) > FLT_EPSILON ||
|
||||
abs(points[1][1] - points[2][1]) > FLT_EPSILON ||
|
||||
abs(points[2][0] - points[3][0]) > FLT_EPSILON ||
|
||||
abs(points[3][1] - points[0][1]) > FLT_EPSILON )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TBlock block( points[0][0], points[0][1], points[2][0], points[2][1] );
|
||||
|
||||
if( block.GetWidth() < block.GetHeight() )
|
||||
{
|
||||
m_VerBlocks.AddTail( block );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_HorBlocks.AddTail( block );
|
||||
}
|
||||
}
|
||||
|
||||
void AddBlock( double x, double y, double width, double height )
|
||||
{
|
||||
TBlock block( x, y, x + width, y + height );
|
||||
|
||||
if( block.GetWidth() < block.GetHeight() )
|
||||
{
|
||||
m_VerBlocks.AddTail( block );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_HorBlocks.AddTail( block );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Calculate()
|
||||
{
|
||||
int nCountHorBlocks = (int)m_HorBlocks.GetCount();
|
||||
int nCountVerBlocks = (int)m_VerBlocks.GetCount();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if( nCountHorBlocks > 1 )
|
||||
{
|
||||
TBlock result;
|
||||
|
||||
POSITION i = m_HorBlocks.GetHeadPosition();
|
||||
while( i != NULL )
|
||||
{
|
||||
TBlock* pCurBlock = &m_HorBlocks.GetAt( i );
|
||||
|
||||
POSITION j = i;
|
||||
m_HorBlocks.GetNext( j );
|
||||
while( j != NULL )
|
||||
{
|
||||
TBlock* pBlock = &m_HorBlocks.GetAt( j );
|
||||
|
||||
if( pCurBlock->Intersect( *pBlock, result ) )
|
||||
{
|
||||
if( result.GetWidth() > result.GetHeight() )
|
||||
{
|
||||
if( pCurBlock->GetHeight() > pBlock->GetHeight() )
|
||||
{
|
||||
POSITION del = i;
|
||||
m_HorBlocks.GetNext( i );
|
||||
m_HorBlocks.RemoveAt( del );
|
||||
pCurBlock = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_HorBlocks.RemoveAt( j );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_HorBlocks.GetNext( j );
|
||||
}
|
||||
|
||||
if( pCurBlock )
|
||||
m_HorBlocks.GetNext( i );
|
||||
}
|
||||
}
|
||||
|
||||
if( nCountVerBlocks > 1 )
|
||||
{
|
||||
TBlock result;
|
||||
|
||||
POSITION i = m_VerBlocks.GetHeadPosition();
|
||||
while( i != NULL )
|
||||
{
|
||||
TBlock* pCurBlock = &m_VerBlocks.GetAt( i );
|
||||
|
||||
POSITION j = i;
|
||||
m_VerBlocks.GetNext( j );
|
||||
while( j != NULL )
|
||||
{
|
||||
TBlock* pBlock = &m_VerBlocks.GetAt( j );
|
||||
|
||||
if( pCurBlock->Intersect( *pBlock, result ) )
|
||||
{
|
||||
if( result.GetHeight() > result.GetWidth() )
|
||||
{
|
||||
if( pCurBlock->GetWidth() > pBlock->GetWidth() )
|
||||
{
|
||||
POSITION del = i;
|
||||
m_VerBlocks.GetNext( i );
|
||||
m_VerBlocks.RemoveAt( del );
|
||||
pCurBlock = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_VerBlocks.RemoveAt( j );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_VerBlocks.GetNext( j );
|
||||
}
|
||||
|
||||
if( pCurBlock )
|
||||
m_VerBlocks.GetNext( i );
|
||||
}
|
||||
}
|
||||
|
||||
nCountHorBlocks = (int)m_HorBlocks.GetCount();
|
||||
nCountVerBlocks = (int)m_VerBlocks.GetCount();
|
||||
|
||||
if( nCountHorBlocks > 1 && nCountVerBlocks > 1 )
|
||||
{
|
||||
CAtlList<TCrossPoint> points;
|
||||
CAtlList<TGroup> groups;
|
||||
|
||||
for( POSITION i = m_HorBlocks.GetHeadPosition(); i != NULL; m_HorBlocks.GetNext( i ) )
|
||||
{
|
||||
TBlock* pHorBlock = &m_HorBlocks.GetAt( i );
|
||||
|
||||
for( POSITION j = m_VerBlocks.GetHeadPosition(); j != NULL; m_VerBlocks.GetNext( j ) )
|
||||
{
|
||||
TBlock* pVerBlock = &m_VerBlocks.GetAt( j );
|
||||
|
||||
if( pHorBlock->Intersect( *pVerBlock ) )
|
||||
{
|
||||
double cx = pVerBlock->GetCenterX();
|
||||
double cy = pHorBlock->GetCenterY();
|
||||
|
||||
points.AddTail( TCrossPoint( cx, cy, pHorBlock, pVerBlock ) );
|
||||
|
||||
TGroup* pHorGroup = pHorBlock->GetGroup();
|
||||
TGroup* pVerGroup = pVerBlock->GetGroup();
|
||||
|
||||
if( pHorGroup == pVerGroup )
|
||||
{
|
||||
if( !pHorGroup )
|
||||
{
|
||||
if( groups.AddTail() )
|
||||
{
|
||||
TGroup* pNewGroup = &groups.GetTail();
|
||||
|
||||
pNewGroup->m_blocks.Add( pHorBlock );
|
||||
pHorBlock->SetGroup( pNewGroup );
|
||||
|
||||
pNewGroup->m_blocks.Add( pVerBlock );
|
||||
pVerBlock->SetGroup( pNewGroup );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !pHorGroup )
|
||||
{
|
||||
pVerGroup->m_blocks.Add( pHorBlock );
|
||||
pHorBlock->SetGroup( pVerGroup );
|
||||
}
|
||||
else if( !pVerGroup )
|
||||
{
|
||||
pHorGroup->m_blocks.Add( pVerBlock );
|
||||
pVerBlock->SetGroup( pHorGroup );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( size_t i = 0; i < pVerGroup->m_blocks.GetCount(); i++ )
|
||||
{
|
||||
pVerGroup->m_blocks[i]->SetGroup( pHorGroup );
|
||||
}
|
||||
|
||||
pHorGroup->m_blocks.Append( pVerGroup->m_blocks );
|
||||
pVerGroup->m_blocks.RemoveAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( POSITION i = points.GetHeadPosition(); i != NULL; points.GetNext( i ) )
|
||||
{
|
||||
TCrossPoint* pPoint = &points.GetAt( i );
|
||||
|
||||
TBlock* pHorBlock = pPoint->m_pHorBlock;
|
||||
TBlock* pVerBlock = pPoint->m_pVerBlock;
|
||||
|
||||
if( pHorBlock->GetGroup() != pVerBlock->GetGroup() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
pHorBlock->GetGroup()->m_points.Add( pPoint );
|
||||
}
|
||||
|
||||
int nCurTable = 0;
|
||||
|
||||
for( POSITION i = groups.GetHeadPosition(); i != NULL; groups.GetNext( i ) )
|
||||
{
|
||||
TGroup* pGroup = &groups.GetAt( i );
|
||||
|
||||
CAtlArray<TCrossPoint*>& data = pGroup->m_points;
|
||||
|
||||
size_t nCountPoints = data.GetCount();
|
||||
if( nCountPoints < 4 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
double* pBufferY = new double[nCountPoints];
|
||||
double* pBufferX = new double[nCountPoints];
|
||||
|
||||
if( pBufferY && pBufferX )
|
||||
{
|
||||
for( size_t k = 0; k < nCountPoints; k++ )
|
||||
{
|
||||
pBufferX[k] = data[k]->m_x;
|
||||
pBufferY[k] = data[k]->m_y;
|
||||
}
|
||||
|
||||
qsort( pBufferX, nCountPoints, sizeof(double), CmpDouble );
|
||||
qsort( pBufferY, nCountPoints, sizeof(double), CmpDouble );
|
||||
|
||||
POSITION pPosTable = m_Tables.AddTail();
|
||||
if( pPosTable )
|
||||
{
|
||||
CTable& table = m_Tables.GetAt( pPosTable );
|
||||
table.SetStartPos( pBufferX[0], pBufferY[0] );
|
||||
|
||||
size_t pos = 0;
|
||||
for( size_t k = 1; k < nCountPoints; k++ )
|
||||
{
|
||||
double d = abs(pBufferX[k] - pBufferX[pos]);
|
||||
|
||||
if( d < 1 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
pos = k;
|
||||
table.AddColumn( d );
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
for( size_t k = 1; k < nCountPoints; k++ )
|
||||
{
|
||||
double d = abs(pBufferY[k] - pBufferY[pos]);
|
||||
|
||||
if( d < 1 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
pos = k;
|
||||
table.AddRow( d );
|
||||
}
|
||||
|
||||
if( table.IsEmpty() )
|
||||
m_Tables.RemoveAt( pPosTable );
|
||||
}
|
||||
}
|
||||
|
||||
delete [] pBufferY;
|
||||
delete [] pBufferX;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CTable* GetFirstTable()
|
||||
{
|
||||
m_pCurTable = m_Tables.GetHeadPosition();
|
||||
|
||||
return GetNextTable();
|
||||
}
|
||||
|
||||
CTable* GetNextTable()
|
||||
{
|
||||
if( !m_pCurTable )
|
||||
return NULL;
|
||||
|
||||
return &m_Tables.GetNext( m_pCurTable );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
static int CmpDouble( const void* p1, const void* p2 )
|
||||
{
|
||||
return (*((double*)p1) <= *((double*)p2)) ? -1 : 1;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
355
AVSEBOOKWriter/Writers/Format.h
Normal file
355
AVSEBOOKWriter/Writers/Format.h
Normal file
@ -0,0 +1,355 @@
|
||||
#pragma once
|
||||
#include "../Common/FontManager.h"
|
||||
#include "../Logic/EbookPage.h"
|
||||
#include "TempManager.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
using namespace NSCommon;
|
||||
|
||||
class CMetadata
|
||||
{
|
||||
public:
|
||||
CString m_strAuthor;
|
||||
CString m_strName;
|
||||
CString m_strPublisher;
|
||||
CString m_strLanguage;
|
||||
|
||||
CString m_strCreatorProgram;
|
||||
|
||||
CString m_strCoverPath;
|
||||
|
||||
CAtlList<IEbookItem*> m_listAnnotation;
|
||||
|
||||
public:
|
||||
CMetadata() : m_listAnnotation()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
m_strAuthor = _T("");
|
||||
m_strName = _T("");
|
||||
m_strPublisher = _T("");
|
||||
m_strLanguage = _T("en");
|
||||
|
||||
m_strCreatorProgram = _T("Online Media Technologies Ltd.");
|
||||
|
||||
m_strCoverPath = _T("");
|
||||
|
||||
POSITION pos = m_listAnnotation.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = m_listAnnotation.GetNext(pos);
|
||||
RELEASEOBJECT(pItem);
|
||||
}
|
||||
m_listAnnotation.RemoveAll();
|
||||
}
|
||||
AVSINLINE void ClearNoAttack()
|
||||
{
|
||||
m_listAnnotation.RemoveAll();
|
||||
}
|
||||
|
||||
~CMetadata()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
CMetadata(const CMetadata& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CMetadata& operator=(const CMetadata& oSrc)
|
||||
{
|
||||
Clear();
|
||||
m_strAuthor = oSrc.m_strAuthor;
|
||||
m_strName = oSrc.m_strName;
|
||||
m_strPublisher = oSrc.m_strPublisher;
|
||||
m_strLanguage = oSrc.m_strLanguage;
|
||||
|
||||
m_strCreatorProgram = oSrc.m_strCreatorProgram;
|
||||
|
||||
m_strCoverPath = oSrc.m_strCoverPath;
|
||||
|
||||
m_listAnnotation.AddHeadList(&oSrc.m_listAnnotation);
|
||||
}
|
||||
};
|
||||
|
||||
class CSection
|
||||
{
|
||||
public:
|
||||
CAtlList<IEbookItem*> m_arTitle;
|
||||
CAtlList<IEbookItem*> m_arItems;
|
||||
|
||||
public:
|
||||
CSection() : m_arTitle(), m_arItems()
|
||||
{
|
||||
}
|
||||
~CSection()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
POSITION pos = m_arItems.GetHeadPosition();
|
||||
while (pos != NULL)
|
||||
{
|
||||
IEbookItem* pItem = m_arItems.GetNext(pos);
|
||||
RELEASEOBJECT(pItem);
|
||||
}
|
||||
m_arItems.RemoveAll();
|
||||
|
||||
pos = m_arTitle.GetHeadPosition();
|
||||
while (pos != NULL)
|
||||
{
|
||||
IEbookItem* pItem = m_arTitle.GetNext(pos);
|
||||
RELEASEOBJECT(pItem);
|
||||
}
|
||||
m_arTitle.RemoveAll();
|
||||
}
|
||||
|
||||
CSection(const CSection& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CSection& operator=(const CSection& oSrc)
|
||||
{
|
||||
Clear();
|
||||
|
||||
m_arItems.AddHeadList(&oSrc.m_arItems);
|
||||
m_arTitle.AddHeadList(&oSrc.m_arTitle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class CNotes
|
||||
{
|
||||
public:
|
||||
CAtlList<IEbookItem*> m_listItems;
|
||||
|
||||
public:
|
||||
CNotes() : m_listItems()
|
||||
{
|
||||
}
|
||||
~CNotes()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
POSITION pos = m_listItems.GetHeadPosition();
|
||||
while (pos != NULL)
|
||||
{
|
||||
IEbookItem* pItem = m_listItems.GetNext(pos);
|
||||
RELEASEOBJECT(pItem);
|
||||
}
|
||||
m_listItems.RemoveAll();
|
||||
}
|
||||
|
||||
CNotes(const CNotes& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CNotes& operator=(const CNotes& oSrc)
|
||||
{
|
||||
Clear();
|
||||
|
||||
m_listItems.AddHeadList(&oSrc.m_listItems);
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class CFormat
|
||||
{
|
||||
public:
|
||||
CMetadata m_oMeta;
|
||||
CAtlList<CSection> m_listSections;
|
||||
CNotes m_oNotes;
|
||||
|
||||
CTempManager m_oTempManager;
|
||||
CImageManager m_oImageManager;
|
||||
|
||||
public:
|
||||
CFormat() : m_oMeta(), m_oNotes(), m_listSections(), m_oTempManager(), m_oImageManager()
|
||||
{
|
||||
}
|
||||
~CFormat()
|
||||
{
|
||||
}
|
||||
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
m_listSections.RemoveAll();
|
||||
m_oNotes.Clear();
|
||||
|
||||
m_oImageManager.NewDocument();
|
||||
}
|
||||
|
||||
void ReadFromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
Clear();
|
||||
|
||||
XmlUtils::CXmlNode oNodeMeta;
|
||||
if (oNode.GetNode(_T("metadata"), oNodeMeta))
|
||||
{
|
||||
m_oMeta.m_strAuthor = oNodeMeta.GetValue(_T("author"));
|
||||
m_oMeta.m_strName = oNodeMeta.GetValue(_T("name"));
|
||||
m_oMeta.m_strPublisher = oNodeMeta.GetValue(_T("publisher"));
|
||||
m_oMeta.m_strCreatorProgram = oNodeMeta.GetValue(_T("creator"));
|
||||
m_oMeta.m_strLanguage = oNodeMeta.GetValue(_T("language"));
|
||||
m_oMeta.m_strCoverPath = oNodeMeta.GetValue(_T("coverpath"));
|
||||
|
||||
XmlUtils::CXmlNode oNodeAnno;
|
||||
if (oNodeMeta.GetNode(_T("annotation"), oNodeAnno))
|
||||
{
|
||||
LoadElements(oNodeAnno, m_oMeta.m_listAnnotation);
|
||||
}
|
||||
}
|
||||
|
||||
XmlUtils::CXmlNodes oNodeSections;
|
||||
if (oNode.GetNodes(_T("sections"), oNodeSections))
|
||||
{
|
||||
int nCount = oNodeSections.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oNodeSection;
|
||||
oNodeSections.GetAt(0, oNodeSection);
|
||||
|
||||
CSection oSection;
|
||||
|
||||
XmlUtils::CXmlNode oTitle;
|
||||
if (oNodeSection.GetNode(_T("title"), oTitle))
|
||||
LoadElements(oTitle, oSection.m_arTitle);
|
||||
|
||||
XmlUtils::CXmlNode oElems;
|
||||
if (oNodeSection.GetNode(_T("items"), oElems))
|
||||
LoadElements(oElems, oSection.m_arItems);
|
||||
|
||||
m_listSections.AddTail(oSection);
|
||||
}
|
||||
}
|
||||
|
||||
XmlUtils::CXmlNode oNodeNotes;
|
||||
if (oNode.GetNode(_T("notes"), oNodeNotes))
|
||||
{
|
||||
LoadElements(oNodeNotes, m_oNotes.m_listItems);
|
||||
}
|
||||
}
|
||||
|
||||
CString SaveToXml()
|
||||
{
|
||||
CString strXml = _T("<ebook>");
|
||||
|
||||
// metadata
|
||||
strXml += (_T("<author>") + m_oMeta.m_strAuthor + _T("</author>"));
|
||||
strXml += (_T("<name>") + m_oMeta.m_strAuthor + _T("</name>"));
|
||||
strXml += (_T("<publisher>") + m_oMeta.m_strAuthor + _T("</publisher>"));
|
||||
strXml += (_T("<creator>") + m_oMeta.m_strAuthor + _T("</creator>"));
|
||||
strXml += (_T("<language>") + m_oMeta.m_strAuthor + _T("</language>"));
|
||||
strXml += (_T("<coverpath>") + m_oMeta.m_strAuthor + _T("</coverpath>"));
|
||||
|
||||
strXml += _T("<annotation>");
|
||||
POSITION pos = m_oMeta.m_listAnnotation.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = m_oMeta.m_listAnnotation.GetNext(pos);
|
||||
strXml += pItem->SaveToXml();
|
||||
}
|
||||
strXml += _T("</annotation>");
|
||||
|
||||
// items
|
||||
strXml += _T("<sections>");
|
||||
pos = m_listSections.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CSection& oSection = m_listSections.GetNext(pos);
|
||||
strXml += _T("<section><title>");
|
||||
|
||||
POSITION pos_ = oSection.m_arTitle.GetHeadPosition();
|
||||
while (NULL != pos_)
|
||||
{
|
||||
IEbookItem* pItem = oSection.m_arTitle.GetNext(pos_);
|
||||
strXml += pItem->SaveToXml();
|
||||
}
|
||||
|
||||
strXml += _T("</title><items>");
|
||||
|
||||
pos_ = oSection.m_arItems.GetHeadPosition();
|
||||
while (NULL != pos_)
|
||||
{
|
||||
IEbookItem* pItem = oSection.m_arItems.GetNext(pos_);
|
||||
strXml += pItem->SaveToXml();
|
||||
}
|
||||
|
||||
strXml += _T("</items></section>");
|
||||
}
|
||||
strXml += _T("</sections>");
|
||||
|
||||
// notes
|
||||
strXml += _T("<notes>");
|
||||
pos = m_oNotes.m_listItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = m_oNotes.m_listItems.GetNext(pos);
|
||||
pItem->SaveToXml();
|
||||
}
|
||||
strXml += _T("</notes>");
|
||||
|
||||
strXml += _T("</ebook>");
|
||||
return strXml;
|
||||
}
|
||||
|
||||
void LoadFromFile(CString strFile)
|
||||
{
|
||||
XmlUtils::CXmlNode oNode;
|
||||
if (oNode.FromXmlFile2(strFile))
|
||||
ReadFromXml(oNode);
|
||||
}
|
||||
void SaveToFile(CString strFile)
|
||||
{
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strFile);
|
||||
oFile.WriteStringUTF8(SaveToXml());
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
static IEbookItem* CreateElementFromNode(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
CString strName = oNode.GetName();
|
||||
IEbookItem* pItem = NULL;
|
||||
if (_T("p") == strName)
|
||||
pItem = new CEbookParagraph();
|
||||
else if (_T("num") == strName)
|
||||
pItem = new CEbookNumbering();
|
||||
else if (_T("table") == strName)
|
||||
pItem = new CEbookTable();
|
||||
else if (_T("graphic") == strName)
|
||||
pItem = new CEbookGraphicObject();
|
||||
|
||||
if (NULL != pItem)
|
||||
pItem->ReadFromXml(oNode);
|
||||
|
||||
return pItem;
|
||||
}
|
||||
static void LoadElements(XmlUtils::CXmlNode& oNode, CAtlList<IEbookItem*>& oArray)
|
||||
{
|
||||
XmlUtils::CXmlNodes oNodes;
|
||||
if (oNode.GetNodes(_T("*"), oNodes))
|
||||
{
|
||||
int nCount = oNodes.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode node;
|
||||
oNodes.GetAt(i, node);
|
||||
IEbookItem* pItem = CreateElementFromNode(node);
|
||||
if (NULL != pItem)
|
||||
oArray.AddTail(pItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
87
AVSEBOOKWriter/Writers/TempManager.h
Normal file
87
AVSEBOOKWriter/Writers/TempManager.h
Normal file
@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
#include "../stdafx.h"
|
||||
#include <time.h>
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
class CTempManager
|
||||
{
|
||||
public:
|
||||
CString m_strTempDirectory;
|
||||
CString m_strTempImagesDirectory;
|
||||
|
||||
public:
|
||||
CTempManager()
|
||||
{
|
||||
m_strTempDirectory = _T("");
|
||||
m_strTempImagesDirectory = _T("");
|
||||
}
|
||||
~CTempManager()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
void InitTempDirectory()
|
||||
{
|
||||
if (_T("") == m_strTempDirectory)
|
||||
{
|
||||
CStringW sTempPath;
|
||||
GetTempPathW(4096, sTempPath.GetBuffer(4096));
|
||||
sTempPath.ReleaseBuffer();
|
||||
|
||||
m_strTempDirectory = sTempPath;
|
||||
}
|
||||
|
||||
srand( (unsigned)time(NULL) );
|
||||
CString sNewDirName;
|
||||
do
|
||||
{
|
||||
int nRandom = rand() % 100000000;
|
||||
CString sRandName;
|
||||
sRandName.Format( _T("AVSEbookTemp%d"), nRandom );
|
||||
sNewDirName = m_strTempDirectory + _T("\\") + sRandName;
|
||||
}
|
||||
while( INVALID_FILE_ATTRIBUTES != ::GetFileAttributes( sNewDirName ) );
|
||||
|
||||
m_strTempDirectory = sNewDirName;
|
||||
m_strTempImagesDirectory = m_strTempDirectory + _T("\\media");
|
||||
|
||||
::CreateDirectory(m_strTempDirectory, NULL);
|
||||
::CreateDirectory(m_strTempImagesDirectory, NULL);
|
||||
}
|
||||
|
||||
void ZipDirectory(CString strDstFile)
|
||||
{
|
||||
AVSOfficeUtils::IOfficeUtils* pOfficeUtils = NULL;
|
||||
if (S_OK != CoCreateInstance(__uuidof(AVSOfficeUtils::COfficeUtils), NULL, CLSCTX_INPROC_SERVER, __uuidof(AVSOfficeUtils::IOfficeUtils),(void**)&pOfficeUtils))
|
||||
return;
|
||||
|
||||
BSTR bstrSrcPath = m_strTempDirectory.AllocSysString();
|
||||
BSTR bstrDstPath = strDstFile.AllocSysString();
|
||||
pOfficeUtils->CompressFileOrDirectory( bstrSrcPath, bstrDstPath, -1 );
|
||||
SysFreeString(bstrSrcPath);
|
||||
SysFreeString(bstrDstPath);
|
||||
RELEASEINTERFACE(pOfficeUtils);
|
||||
}
|
||||
|
||||
void RemoveTempDirectory()
|
||||
{
|
||||
if ( _T("") == m_strTempDirectory )
|
||||
return;
|
||||
|
||||
SHFILEOPSTRUCTW shfos;
|
||||
ZeroMemory(&shfos, sizeof(shfos));
|
||||
shfos.wFunc = FO_DELETE;
|
||||
CStringW _local = m_strTempDirectory + L"*.*";
|
||||
_local.AppendChar(0);
|
||||
_local.AppendChar(0);
|
||||
shfos.pFrom = _local.GetString();
|
||||
shfos.fFlags = FOF_SILENT + FOF_NOCONFIRMATION;
|
||||
|
||||
SHFileOperationW(&shfos);
|
||||
RemoveDirectory(m_strTempDirectory);
|
||||
|
||||
m_strTempDirectory = _T("");
|
||||
}
|
||||
};
|
||||
}
|
||||
275
AVSEBOOKWriter/Writers/Writer.h
Normal file
275
AVSEBOOKWriter/Writers/Writer.h
Normal file
@ -0,0 +1,275 @@
|
||||
#pragma once
|
||||
#include "Format.h"
|
||||
#include "../Logic/LogicPage.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CWriter
|
||||
{
|
||||
public:
|
||||
LONG m_lCurrentPageIndex;
|
||||
LONG m_lCountPages;
|
||||
|
||||
ILogicPage* m_pCurrentPage;
|
||||
CFormat m_oFormat;
|
||||
|
||||
CString m_strSrcFileName;
|
||||
|
||||
bool m_bIsSaveCover;
|
||||
bool m_bIsEmbeddedFonts;
|
||||
bool m_bIsSrcCoverExist;
|
||||
|
||||
AVSGraphics::IAVSEffectPainter* m_pPainter;
|
||||
public:
|
||||
CWriter()
|
||||
{
|
||||
m_pCurrentPage = NULL;
|
||||
m_pPainter = NULL;
|
||||
|
||||
m_lCurrentPageIndex = -1;
|
||||
m_lCountPages = 0;
|
||||
|
||||
m_strSrcFileName = _T("");
|
||||
|
||||
m_bIsSaveCover = true;
|
||||
m_bIsEmbeddedFonts = true;
|
||||
m_bIsSrcCoverExist = false;
|
||||
}
|
||||
~CWriter()
|
||||
{
|
||||
RELEASEINTERFACE(m_pPainter);
|
||||
}
|
||||
|
||||
CRenderers* CreateDocument(LONG lSrcType, LONG lDstType)
|
||||
{
|
||||
RELEASEOBJECT(m_pCurrentPage);
|
||||
m_oFormat.Clear();
|
||||
m_oFormat.m_oTempManager.InitTempDirectory();
|
||||
if (0 == lSrcType)
|
||||
{
|
||||
m_pCurrentPage = new CLogicPageDOCX();
|
||||
m_pCurrentPage->m_pImageManager = &m_oFormat.m_oImageManager;
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pCurrentPage = new CLogicPagePDF();
|
||||
CLogicPagePDF* pPagePDF = (CLogicPagePDF*)m_pCurrentPage;
|
||||
m_pCurrentPage->m_pImageManager = &m_oFormat.m_oImageManager;
|
||||
return &pPagePDF->m_oRenderers;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SetParametres(NSStructures::CPen* pPen, NSStructures::CBrush* pBrush, NSStructures::CFont* pFont,
|
||||
NSStructures::CShadow* pShadow, NSStructures::CEdgeText* pEdge,
|
||||
AVSGraphics::IAVSGraphicSimpleComverter* pSimpleConverter, NSCommon::CMatrix* pTransform)
|
||||
{
|
||||
m_pCurrentPage->m_pPen = pPen;
|
||||
m_pCurrentPage->m_pBrush = pBrush;
|
||||
m_pCurrentPage->m_pFont = pFont;
|
||||
m_pCurrentPage->m_pShadow = pShadow;
|
||||
m_pCurrentPage->m_pEdgeText = pEdge;
|
||||
|
||||
m_pCurrentPage->m_pSimpleGraphicsConverter = pSimpleConverter;
|
||||
m_pCurrentPage->m_pTransform = pTransform;
|
||||
|
||||
m_pCurrentPage->InitProp();
|
||||
|
||||
m_oFormat.m_oImageManager.m_strDstMedia = m_oFormat.m_oTempManager.m_strTempImagesDirectory;
|
||||
}
|
||||
|
||||
void CloseFile()
|
||||
{
|
||||
RELEASEOBJECT(m_pCurrentPage);
|
||||
m_oFormat.Clear();
|
||||
m_oFormat.m_oTempManager.RemoveTempDirectory();
|
||||
}
|
||||
void EndFile()
|
||||
{
|
||||
m_pCurrentPage->CloseFile(m_oFormat);
|
||||
}
|
||||
|
||||
void BeginPage(double dWidth, double dHeight)
|
||||
{
|
||||
++m_lCurrentPageIndex;
|
||||
if (0 != m_lCurrentPageIndex)
|
||||
m_pCurrentPage->Clear();
|
||||
|
||||
m_pCurrentPage->m_dWidth = dWidth;
|
||||
m_pCurrentPage->m_dHeight = dHeight;
|
||||
m_pCurrentPage->BeginPage();
|
||||
|
||||
m_pCurrentPage->m_pPen->SetDefaultParams();
|
||||
m_pCurrentPage->m_pBrush->SetDefaultParams();
|
||||
m_pCurrentPage->m_pFont->SetDefaultParams();
|
||||
}
|
||||
void EndPage()
|
||||
{
|
||||
m_pCurrentPage->EndPage();
|
||||
m_pCurrentPage->ConvertToEbookPage(m_oFormat);
|
||||
|
||||
m_pCurrentPage->Clear();
|
||||
}
|
||||
|
||||
public:
|
||||
AVSINLINE void MoveTo(double& x, double& y)
|
||||
{
|
||||
m_pCurrentPage->MoveTo(x, y);
|
||||
}
|
||||
AVSINLINE void LineTo(double& x, double& y)
|
||||
{
|
||||
m_pCurrentPage->LineTo(x, y);
|
||||
}
|
||||
AVSINLINE void CurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
|
||||
{
|
||||
m_pCurrentPage->CurveTo(x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
AVSINLINE void Close()
|
||||
{
|
||||
m_pCurrentPage->Close();
|
||||
}
|
||||
AVSINLINE void BeginPath()
|
||||
{
|
||||
m_pCurrentPage->BeginPath();
|
||||
}
|
||||
AVSINLINE void EndPath()
|
||||
{
|
||||
m_pCurrentPage->EndPath();
|
||||
}
|
||||
AVSINLINE void WriteText(BSTR bsText, BSTR bsGid, double& x, double& y, double& width, double& height, double& baselineoffset)
|
||||
{
|
||||
m_pCurrentPage->WriteText(bsText, bsGid, x, y, width, height, baselineoffset);
|
||||
}
|
||||
AVSINLINE void WriteImage(IUnknown* punkImage, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
size_t nCountImages = m_oFormat.m_oImageManager.m_listImages.GetCount();
|
||||
if (m_bIsSaveCover && (0 == nCountImages))
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
double _x = 0;
|
||||
double _y = 0;
|
||||
double _w = 210;
|
||||
double _h = 297;
|
||||
m_oFormat.m_oImageManager.WriteImage(punkImage, _x, _y, _w, _h);
|
||||
return;
|
||||
}
|
||||
else if ((0 == nCountImages) && m_bIsSrcCoverExist)
|
||||
{
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
return;
|
||||
}
|
||||
|
||||
m_pCurrentPage->WriteImage(punkImage, x, y, width, height);
|
||||
}
|
||||
AVSINLINE void WriteImage(CString strFilePath, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
size_t nCountImages = m_oFormat.m_oImageManager.m_listImages.GetCount();
|
||||
if (m_bIsSaveCover && (0 == nCountImages))
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
double _x = 0;
|
||||
double _y = 0;
|
||||
double _w = 210;
|
||||
double _h = 297;
|
||||
m_oFormat.m_oImageManager.WriteImage(strFilePath, _x, _y, _w, _h);
|
||||
return;
|
||||
}
|
||||
else if ((0 == nCountImages) && m_bIsSrcCoverExist)
|
||||
{
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
return;
|
||||
}
|
||||
|
||||
m_pCurrentPage->WriteImage(strFilePath, x, y, width, height);
|
||||
}
|
||||
AVSINLINE void WriteTable(NSEBook::ILogicItem* pItem)
|
||||
{
|
||||
m_pCurrentPage->WriteTable(pItem);
|
||||
}
|
||||
AVSINLINE void BeginShape()
|
||||
{
|
||||
m_pCurrentPage->BeginShape();
|
||||
}
|
||||
AVSINLINE void EndShape()
|
||||
{
|
||||
m_pCurrentPage->EndShape();
|
||||
}
|
||||
AVSINLINE void DrawPath(long nType)
|
||||
{
|
||||
m_pCurrentPage->DrawPath(nType);
|
||||
}
|
||||
|
||||
public:
|
||||
void InitWatermark()
|
||||
{
|
||||
if (NULL == m_pCurrentPage)
|
||||
return;
|
||||
|
||||
if (NULL == m_pPainter)
|
||||
{
|
||||
m_pCurrentPage->m_oInfoWatermark.m_lID = -1;
|
||||
m_pCurrentPage->m_oRectWatermark.left = 0;
|
||||
m_pCurrentPage->m_oRectWatermark.top = 0;
|
||||
m_pCurrentPage->m_oRectWatermark.right = 0;
|
||||
m_pCurrentPage->m_oRectWatermark.bottom = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LONG lWidthPix = 400;
|
||||
LONG lHeightPix = 75;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
CoCreateInstance(MediaCore::CLSID_CAVSUncompressedVideoFrame, NULL, CLSCTX_ALL,
|
||||
MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
pFrame->put_ColorSpace( ( 1 << 6) | ( 1 << 31) ); // CPS_BGRA | CPS_FLIP
|
||||
pFrame->put_Width( lWidthPix );
|
||||
pFrame->put_Height( lHeightPix );
|
||||
pFrame->put_AspectRatioX( lWidthPix );
|
||||
pFrame->put_AspectRatioY( lHeightPix );
|
||||
pFrame->put_Interlaced( VARIANT_FALSE );
|
||||
pFrame->put_Stride( 0, 4 * lWidthPix );
|
||||
pFrame->AllocateBuffer( -1 );
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
pFrame->get_Buffer(&pBuffer);
|
||||
memset(pBuffer, 0xFF, 4 * lWidthPix * lHeightPix);
|
||||
|
||||
AVSGraphics::IAVSGraphicsRenderer* pRenderer = NULL;
|
||||
CoCreateInstance(AVSGraphics::CLSID_CAVSGraphicsRenderer, NULL, CLSCTX_ALL,
|
||||
AVSGraphics::IID_IAVSGraphicsRenderer, (void**)&pRenderer);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FontManager
|
||||
VARIANT vtVariant;
|
||||
vtVariant.vt = VT_UNKNOWN;
|
||||
vtVariant.punkVal = NULL;
|
||||
pRenderer->SetAdditionalParam( L"FontManager", vtVariant );
|
||||
|
||||
IUnknown* punkWatermark = NULL;
|
||||
pFrame->QueryInterface(IID_IUnknown, (void**)&punkWatermark);
|
||||
|
||||
pRenderer->put_Width(140);
|
||||
pRenderer->put_Height(30);
|
||||
pRenderer->CreateFromMediaData(punkWatermark, 0, 0, lWidthPix, lHeightPix);
|
||||
|
||||
m_pPainter->Draw((IUnknown*)pRenderer);
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
RELEASEINTERFACE(pRenderer);
|
||||
|
||||
m_pCurrentPage->m_oRectWatermark.left = 0;
|
||||
m_pCurrentPage->m_oRectWatermark.top = 0;
|
||||
m_pCurrentPage->m_oRectWatermark.right = 140;
|
||||
m_pCurrentPage->m_oRectWatermark.bottom = 30;
|
||||
|
||||
double _x = 0;
|
||||
double _y = 0;
|
||||
double _w = 140;
|
||||
double _h = 30;
|
||||
|
||||
m_pCurrentPage->m_oInfoWatermark = m_oFormat.m_oImageManager.WriteImage(punkWatermark, _x, _y, _w, _h);
|
||||
}
|
||||
};
|
||||
}
|
||||
16
AVSEBOOKWriter/Writers/Writer_Docx.h
Normal file
16
AVSEBOOKWriter/Writers/Writer_Docx.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "Writer.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CWriter_Docx
|
||||
{
|
||||
public:
|
||||
void CreateDocument(CWriter* pWriter)
|
||||
{
|
||||
}
|
||||
void CloseFile(CString strDstFile, CWriter* pWriter)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
706
AVSEBOOKWriter/Writers/Writer_Epub.h
Normal file
706
AVSEBOOKWriter/Writers/Writer_Epub.h
Normal file
@ -0,0 +1,706 @@
|
||||
#pragma once
|
||||
#include "Writer.h"
|
||||
|
||||
#define CODEPAGE_ISSUE_FIX
|
||||
#include "../AVSOfficeUtils/ZLIB/zlib-1.2.3/contrib/minizip/zip.h"
|
||||
|
||||
#define BUFSIZE 2048
|
||||
#define MAXHTMLSIZE 130000 // 130000 bytes
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CWriter_Epub
|
||||
{
|
||||
private:
|
||||
NSCommon::CStringWriter m_oWriter;
|
||||
NSCommon::CStringWriter m_oWriterTOC;
|
||||
NSCommon::CStringWriter m_oWriterTOCReferenses;
|
||||
LONG m_lCurrentHtml;
|
||||
|
||||
CFormat* m_pFormat;
|
||||
LONG m_lSectionWrite;
|
||||
|
||||
CString m_strFontsItems;
|
||||
bool m_bIsFontsEmbedded;
|
||||
bool m_bIsSaveCover;
|
||||
|
||||
public:
|
||||
void CreateDocument(CWriter* pWriter)
|
||||
{
|
||||
m_bIsFontsEmbedded = pWriter->m_bIsEmbeddedFonts;
|
||||
m_bIsSaveCover = pWriter->m_bIsSaveCover;
|
||||
|
||||
m_lSectionWrite = 1;
|
||||
m_lCurrentHtml = 1;
|
||||
|
||||
// METAINF
|
||||
CString strMETA_INF = pWriter->m_oFormat.m_oTempManager.m_strTempDirectory + _T("\\META-INF");
|
||||
CDirectory::CreateDirectory(strMETA_INF);
|
||||
CString str1 = _T("<?xml version=\"1.0\"?><container version=\"1.0\" xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\">\
|
||||
<rootfiles><rootfile full-path=\"content.opf\" media-type=\"application/oebps-package+xml\"/></rootfiles></container>");
|
||||
CFile oFile1;
|
||||
oFile1.CreateFile(strMETA_INF + _T("\\container.xml"));
|
||||
oFile1.WriteStringUTF8(str1);
|
||||
oFile1.CloseFile();
|
||||
|
||||
// mimetype
|
||||
CStringA str2 = "application/epub+zip";
|
||||
CFile oFile2;
|
||||
oFile2.CreateFile(pWriter->m_oFormat.m_oTempManager.m_strTempDirectory + _T("\\mimetype"));
|
||||
oFile2.WriteFile((void*)str2.GetBuffer(), str2.GetLength());
|
||||
oFile2.CloseFile();
|
||||
|
||||
// css
|
||||
CString strCSS = _T(".heading1 { text-align: center; font-weight: bold; font-size: 2em; }\n\
|
||||
.heading2 { text-align: center; font-weight: bold; font-size: 1.5em; }n\
|
||||
.heading0 { text-indent: 2em; text-align: justify; font-size: 1em; }\n\
|
||||
.image_inline { vertical-align: baseline; }\n\
|
||||
.image_block { vertical-align: baseline; }\n\
|
||||
.bookpagebreak { display: block; page-break-after:always; margin-bottom: 0; margin-left: 0; margin-right: 0; margin-top: 0 }\n\
|
||||
p {text-indent: 1.5em; }\n\
|
||||
.main { display: block; font-size: 1em; margin-bottom: 0; margin-left: 5pt; margin-right: 5pt; margin-top: 0; padding-left: 0; padding-right: 0; text-align: justify }\n\
|
||||
.hyper { text-decoration: underline; }\n");
|
||||
|
||||
if (m_bIsFontsEmbedded && (NULL != pWriter->m_pCurrentPage))
|
||||
{
|
||||
::CreateDirectory(pWriter->m_oFormat.m_oTempManager.m_strTempDirectory + _T("\\fonts"), NULL);
|
||||
|
||||
CString strCssMem = _T("");
|
||||
m_strFontsItems = _T("");
|
||||
pWriter->m_pCurrentPage->m_oFontsGen.WriteFonts(pWriter->m_oFormat.m_oTempManager.m_strTempDirectory, strCssMem, m_strFontsItems);
|
||||
|
||||
strCSS += strCssMem;
|
||||
}
|
||||
|
||||
CFile oFile3;
|
||||
oFile3.CreateFile(pWriter->m_oFormat.m_oTempManager.m_strTempDirectory + _T("\\stylesheet.css"));
|
||||
oFile3.WriteStringUTF8(strCSS);
|
||||
oFile3.CloseFile();
|
||||
|
||||
m_pFormat = &pWriter->m_oFormat;
|
||||
POSITION posSect = m_pFormat->m_listSections.GetHeadPosition();
|
||||
while (NULL != posSect)
|
||||
{
|
||||
if (1 != m_lCurrentHtml)
|
||||
DumpCurrentHtml(m_pFormat);
|
||||
|
||||
CSection& oSection = m_pFormat->m_listSections.GetNext(posSect);
|
||||
DumpSection(&oSection);
|
||||
|
||||
POSITION pos = oSection.m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = oSection.m_arItems.GetNext(pos);
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case IEbookItem::ebitParagraph:
|
||||
{
|
||||
WriteParagraph((CEbookParagraph*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitTable:
|
||||
{
|
||||
WriteTable((CEbookTable*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitGraphic:
|
||||
{
|
||||
WriteImage((CEbookGraphicObject*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitNumbering:
|
||||
{
|
||||
WriteNumbering((CEbookNumbering*)pItem);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DumpCurrentHtml(m_pFormat, true);
|
||||
}
|
||||
void CloseFile(CString strDstFile, CWriter* pWriter)
|
||||
{
|
||||
WriteOPF(m_pFormat);
|
||||
CompressEpubDir(pWriter->m_oFormat.m_oTempManager.m_strTempDirectory, strDstFile);
|
||||
}
|
||||
|
||||
void DumpSection(CSection* pSection)
|
||||
{
|
||||
DumpCurrentHtml(m_pFormat, true);
|
||||
|
||||
CString strText = _T("");
|
||||
POSITION pos = pSection->m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = pSection->m_arItems.GetNext(pos);
|
||||
if (IEbookItem::ebitParagraph == pItem->m_eType)
|
||||
{
|
||||
CEbookParagraph* pParagraph = (CEbookParagraph*)pItem;
|
||||
strText = pParagraph->GetAllText();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CorrectString(strText);
|
||||
|
||||
GUID guid;
|
||||
CoCreateGuid(&guid);
|
||||
CString strGuid = _T("");
|
||||
strGuid.Format(_T("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"), guid.Data1, guid.Data2, guid.Data3,
|
||||
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
||||
|
||||
|
||||
CString s1 = _T("");
|
||||
s1.Format(_T("%d"), m_lSectionWrite++);
|
||||
CString s2 = _T("");
|
||||
s2.Format(_T("%d"), m_lCurrentHtml);
|
||||
|
||||
CString strSect = _T("<navPoint class=\"chapter\" id=\"") + strGuid + _T("\" playOrder=\"") + s1 + _T("\"><navLabel><text>") + strText +
|
||||
_T("</text></navLabel><content src=\"content_") + s2 + _T(".xhtml\"/></navPoint>");
|
||||
|
||||
m_oWriterTOC.WriteStringC(strSect);
|
||||
|
||||
CString strSectRef = _T("<p><a href=\"content_") + s2 + _T(".xhtml\"><span class=\"hyper\">") + strText + _T("</span></a></p>");
|
||||
m_oWriterTOCReferenses.WriteStringC(strSectRef);
|
||||
|
||||
}
|
||||
|
||||
void DumpCurrentHtml(NSEBook::CFormat* pFormat, bool bIsEnd = false)
|
||||
{
|
||||
if (bIsEnd)
|
||||
{
|
||||
if (0 == m_oWriter.GetCurSize())
|
||||
return;
|
||||
}
|
||||
|
||||
CString str1 = _T("<?xml version=\"1.0\" encoding=\"utf-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>") +
|
||||
pFormat->m_oMeta.m_strName + _T("</title><meta content=\"http://www.w3.org/1999/xhtml; charset=utf-8\" http-equiv=\"Content-Type\"/>\
|
||||
<link href=\"stylesheet.css\" type=\"text/css\" rel=\"stylesheet\"/><style type=\"text/css\"></style></head><body class=\"main\">");
|
||||
|
||||
CString str2 = _T("</body></html>");
|
||||
|
||||
CString strNum = _T("");
|
||||
|
||||
strNum.Format(_T("%d"), m_lCurrentHtml);
|
||||
|
||||
++m_lCurrentHtml;
|
||||
CString strSave = pFormat->m_oTempManager.m_strTempDirectory + _T("\\content_") + strNum + _T(".xhtml");
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strSave);
|
||||
BYTE utf8_mem[3];
|
||||
utf8_mem[0] = 0xEF;
|
||||
utf8_mem[1] = 0xBB;
|
||||
utf8_mem[2] = 0xBF;
|
||||
|
||||
oFile.WriteFile((void*)utf8_mem, 3);
|
||||
oFile.WriteStringUTF8(str1);
|
||||
|
||||
CString strBody = m_oWriter.GetCString();
|
||||
oFile.WriteStringUTF8(strBody);
|
||||
|
||||
oFile.WriteStringUTF8(str2);
|
||||
oFile.CloseFile();
|
||||
|
||||
m_oWriter.ClearNoAttack();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
static CStringA UnicodeToCodepage( CStringW sUni, UINT nCodepage = CP_UTF8 )
|
||||
{
|
||||
CStringA sUtf;
|
||||
int nBufSize = WideCharToMultiByte(nCodepage, 0, sUni, -1, NULL, NULL, NULL, NULL);
|
||||
LPSTR pBuff = new CHAR[ nBufSize + 1 ];
|
||||
WideCharToMultiByte(nCodepage, 0, sUni, -1, pBuff, nBufSize, NULL, NULL);
|
||||
pBuff[ nBufSize ] = 0;
|
||||
sUtf.Append( pBuff );
|
||||
delete pBuff;
|
||||
return sUtf;
|
||||
}
|
||||
|
||||
int _WriteFileToZip( CString sSource, CString sSourceRel, zipFile zf, int nCompressionLevel )
|
||||
{
|
||||
int err = 0;
|
||||
if( Z_NO_COMPRESSION == nCompressionLevel )
|
||||
err = zipOpenNewFileInZip( zf, UnicodeToCodepage (sSourceRel, CP_OEMCP), NULL, NULL, 0, NULL, 0, NULL, NULL, nCompressionLevel );
|
||||
else
|
||||
err = zipOpenNewFileInZip( zf, UnicodeToCodepage (sSourceRel, CP_OEMCP), NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, nCompressionLevel );
|
||||
HANDLE hSourceFile = ::CreateFile( sSource, GENERIC_READ, 0, 0, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if( INVALID_HANDLE_VALUE == hSourceFile )
|
||||
err = -1;
|
||||
DWORD dwBytesRead = 1;
|
||||
BYTE bBuffer[ BUFSIZE ];
|
||||
while( -1 != err && 0 != dwBytesRead )
|
||||
{
|
||||
ReadFile( hSourceFile, bBuffer, BUFSIZE, &dwBytesRead, NULL );
|
||||
if( dwBytesRead > 0 )
|
||||
err = zipWriteInFileInZip( zf, bBuffer, dwBytesRead );
|
||||
}
|
||||
RELEASEHANDLE( hSourceFile );
|
||||
if( 0 == err )
|
||||
err = zipCloseFileInZip( zf );
|
||||
else
|
||||
zipCloseFileInZip( zf );
|
||||
return err;
|
||||
}
|
||||
|
||||
int _CompressEpubDir( CString sSource, CString sPathRel, zipFile zf, int nCompresstionLevel )
|
||||
{
|
||||
DWORD dwFileAttrib = ::GetFileAttributes( sSource );
|
||||
if( dwFileAttrib != INVALID_FILE_ATTRIBUTES )
|
||||
{
|
||||
DWORD dwResult = 0;
|
||||
if( 0 != (FILE_ATTRIBUTE_DIRECTORY & dwFileAttrib) )
|
||||
{
|
||||
HANDLE Handle;
|
||||
WIN32_FIND_DATA FindData;
|
||||
DWORDLONG Result = 0;
|
||||
|
||||
Handle = FindFirstFile( ( sSource + _T("\\*.*") ), &FindData );
|
||||
if ( Handle == INVALID_HANDLE_VALUE )
|
||||
return 0;
|
||||
do
|
||||
{
|
||||
int nRes = 0;
|
||||
if( ( CString( FindData.cFileName ) != _T("mimetype") ) && ( CString( FindData.cFileName ) != _T(".") ) && ( CString( FindData.cFileName ) != _T("..") ) )
|
||||
{
|
||||
if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
|
||||
{
|
||||
if( _T("fonts") == CString( FindData.cFileName ) )
|
||||
dwResult += _CompressEpubDir( sSource + _T("\\") + FindData.cFileName, sPathRel + FindData.cFileName + _T("/"), zf, Z_NO_COMPRESSION );//<2F><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else
|
||||
dwResult += _CompressEpubDir( sSource + _T("\\") + FindData.cFileName, sPathRel + FindData.cFileName + _T("/"), zf, nCompresstionLevel );
|
||||
}
|
||||
else
|
||||
dwResult += _CompressEpubDir( sSource + _T("\\") + FindData.cFileName, sPathRel, zf, nCompresstionLevel );
|
||||
}
|
||||
}
|
||||
while( FindNextFile( Handle, &FindData ) != 0 );
|
||||
FindClose( Handle );
|
||||
}
|
||||
else
|
||||
{
|
||||
TCHAR tExt[256];
|
||||
TCHAR tFilename[256];
|
||||
_wsplitpath( sSource, NULL, NULL, tFilename, tExt );
|
||||
CString sExt = tExt;
|
||||
CString sFilename = tFilename;
|
||||
|
||||
_WriteFileToZip( sSource, sPathRel + sFilename + sExt, zf, nCompresstionLevel );
|
||||
}
|
||||
|
||||
return dwResult;
|
||||
}// 0 - <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
return 0;
|
||||
}
|
||||
int CompressEpubDir( CString sSource, CString sDestination )
|
||||
{
|
||||
int err = 0;
|
||||
zipFile zf = zipOpen( sDestination, APPEND_STATUS_CREATE );
|
||||
if( NULL == zf )
|
||||
return 1;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> mimetype
|
||||
CString sMimeFile = sSource + _T("\\mimetype");
|
||||
if( ::GetFileAttributes( sMimeFile ) != INVALID_FILE_ATTRIBUTES )
|
||||
err = _WriteFileToZip( sMimeFile, _T("mimetype"), zf, Z_NO_COMPRESSION );
|
||||
|
||||
if( err == 0 )
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
err = _CompressEpubDir( sSource, _T(""), zf, Z_BEST_COMPRESSION );
|
||||
}
|
||||
if( 0 == err )
|
||||
err = zipClose( zf, NULL );
|
||||
else
|
||||
zipClose( zf, NULL );
|
||||
return err;
|
||||
}
|
||||
|
||||
void WriteOPF(NSEBook::CFormat* pFormat)
|
||||
{
|
||||
NSCommon::CStringWriter oOpf;
|
||||
oOpf.WriteStringC(_T("<?xml version='1.0' encoding='utf-8'?><package xmlns=\"http://www.idpf.org/2007/opf\" version=\"2.0\"\
|
||||
unique-identifier=\"bookid\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:opf=\"http://www.idpf.org/2007/opf\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
|
||||
xmlns:dcterms=\"http://purl.org/dc/terms/\"><metadata>"));
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:publisher>"));
|
||||
oOpf.WriteStringC(CorrectString2(pFormat->m_oMeta.m_strPublisher));
|
||||
oOpf.WriteStringC(_T("</dc:publisher>"));
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:language>"));
|
||||
//oOpf.WriteStringC(CorrectString2(pFormat->m_oMeta.m_strLanguage));
|
||||
oOpf.WriteStringC(_T("</dc:language>"));
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:creator>"));
|
||||
oOpf.WriteStringC(CorrectString2(pFormat->m_oMeta.m_strAuthor));
|
||||
oOpf.WriteStringC(_T("</dc:creator>"));
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:title>"));
|
||||
oOpf.WriteStringC(CorrectString2(pFormat->m_oMeta.m_strName));
|
||||
oOpf.WriteStringC(_T("</dc:title>"));
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:contributor>"));
|
||||
oOpf.WriteStringC(CorrectString2(pFormat->m_oMeta.m_strCreatorProgram));
|
||||
oOpf.WriteStringC(_T("</dc:contributor>"));
|
||||
|
||||
if (0 != pFormat->m_oMeta.m_listAnnotation.GetCount())
|
||||
{
|
||||
oOpf.WriteStringC(_T("<dc:description>"));
|
||||
|
||||
POSITION pos = pFormat->m_oMeta.m_listAnnotation.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = pFormat->m_oMeta.m_listAnnotation.GetNext(pos);
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case IEbookItem::ebitParagraph:
|
||||
{
|
||||
CEbookParagraph* pPar = (CEbookParagraph*)pItem;
|
||||
oOpf.WriteStringC(CorrectString2(pPar->GetAllText()));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
oOpf.WriteStringC(_T("</dc:description>"));
|
||||
}
|
||||
|
||||
GUID guid;
|
||||
CoCreateGuid(&guid);
|
||||
CString strGuid = _T("");
|
||||
strGuid.Format(_T("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"), guid.Data1, guid.Data2, guid.Data3,
|
||||
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:identifier id=\"bookid\" opf:scheme=\"uuid\">"));
|
||||
oOpf.WriteStringC(strGuid);
|
||||
oOpf.WriteStringC(_T("</dc:identifier>"));
|
||||
|
||||
if (m_bIsSaveCover)
|
||||
{
|
||||
LONG _lStartImage = max(m_lCurrentHtml, 1000);
|
||||
CString strCover = _T("");
|
||||
strCover.Format(_T("id%d"), _lStartImage);
|
||||
m_oWriter.WriteString(_T("<meta name=\"cover\" content=\"") + strCover + _T("\"/>"));
|
||||
}
|
||||
|
||||
oOpf.WriteStringC(_T("</metadata><manifest><opf:item id=\"ncx\" href=\"toc.ncx\" media-type=\"application/x-dtbncx+xml\"/>\
|
||||
<item href=\"book_toc.xhtml\" id=\"book_toc_id\" media-type=\"application/xhtml+xml\"/>\
|
||||
<item href=\"stylesheet.css\" id=\"css\" media-type=\"text/css\"/>"));
|
||||
|
||||
if (m_bIsSaveCover)
|
||||
{
|
||||
oOpf.WriteStringC(_T("<item id=\"cover\" href=\"cover.xhtml\" media-type=\"application/xhtml+xml\"/>"));
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> xhtml
|
||||
CFile oFileCover;
|
||||
oFileCover.CreateFile(pFormat->m_oTempManager.m_strTempDirectory + _T("\\cover.xhtml"));
|
||||
BYTE utf8_mem[3];
|
||||
utf8_mem[0] = 0xEF;
|
||||
utf8_mem[1] = 0xBB;
|
||||
utf8_mem[2] = 0xBF;
|
||||
|
||||
bool bIsPNG = false;
|
||||
if (0 != pFormat->m_oImageManager.m_listImages.GetCount())
|
||||
{
|
||||
if (NSCommon::itPNG == pFormat->m_oImageManager.m_listImages.GetHead().m_eType)
|
||||
bIsPNG = true;
|
||||
}
|
||||
|
||||
oFileCover.WriteFile((void*)utf8_mem, 3);
|
||||
|
||||
if (!bIsPNG)
|
||||
{
|
||||
CString strCoverXHTML = _T("<?xml version=\"1.0\" encoding=\"utf-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\">\
|
||||
<head><title>Cover</title></head><body><div class=\"coverpage\">\
|
||||
<img style=\"width:100%;height: 100%;\" alt=\"Cover\" src=\"media/image1.jpg\"/></div></body></html>");
|
||||
|
||||
oFileCover.WriteStringUTF8(strCoverXHTML);
|
||||
}
|
||||
else
|
||||
{
|
||||
CString strCoverXHTML = _T("<?xml version=\"1.0\" encoding=\"utf-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\">\
|
||||
<head><title>Cover</title></head><body><div class=\"coverpage\">\
|
||||
<img style=\"width:100%;height: 100%;\" alt=\"Cover\" src=\"media/image1.png\"/></div></body></html>");
|
||||
|
||||
oFileCover.WriteStringUTF8(strCoverXHTML);
|
||||
}
|
||||
oFileCover.CloseFile();
|
||||
}
|
||||
|
||||
for (LONG lStartText = 1; lStartText < m_lCurrentHtml; ++lStartText)
|
||||
{
|
||||
CString strText = _T("");
|
||||
strText.Format(_T("<item href=\"content_%d.xhtml\" id=\"id%d\" media-type=\"application/xhtml+xml\"/>"), lStartText, lStartText);
|
||||
oOpf.WriteStringC(strText);
|
||||
}
|
||||
|
||||
LONG lStartImage = max(m_lCurrentHtml, 1000);
|
||||
POSITION posImage = pFormat->m_oImageManager.m_listImages.GetHeadPosition();
|
||||
while (NULL != posImage)
|
||||
{
|
||||
CImageInfo& info = pFormat->m_oImageManager.m_listImages.GetNext(posImage);
|
||||
|
||||
if (itJPG == info.m_eType)
|
||||
{
|
||||
CString strText = _T("");
|
||||
strText.Format(_T("<item href=\"media/image%d.jpg\" id=\"id%d\" media-type=\"image/jpeg\"/>"), info.m_lID, lStartImage);
|
||||
oOpf.WriteStringC(strText);
|
||||
}
|
||||
else
|
||||
{
|
||||
CString strText = _T("");
|
||||
strText.Format(_T("<item href=\"media/%d.png\" id=\"id%d\" media-type=\"image/png\"/>"), info.m_lID, lStartImage);
|
||||
oOpf.WriteStringC(strText);
|
||||
}
|
||||
++lStartImage;
|
||||
}
|
||||
|
||||
oOpf.WriteStringC(m_strFontsItems);
|
||||
|
||||
oOpf.WriteStringC(_T("</manifest><spine toc=\"ncx\">"));
|
||||
|
||||
if (m_bIsSaveCover)
|
||||
{
|
||||
oOpf.WriteStringC(_T("<itemref idref=\"cover\"/>"));
|
||||
}
|
||||
|
||||
for (LONG i = 1; i < m_lCurrentHtml; ++i)
|
||||
{
|
||||
CString strText = _T("");
|
||||
strText.Format(_T("<itemref idref=\"id%d\"/>"), i);
|
||||
oOpf.WriteStringC(strText);
|
||||
}
|
||||
if (FALSE)
|
||||
{
|
||||
oOpf.WriteStringC(_T("<itemref idref=\"book_toc_id\"/>"));
|
||||
}
|
||||
|
||||
oOpf.WriteStringC(_T("</spine><guide><reference href=\"book_toc.xhtml#maintoc\" type=\"toc\" title=\"Table of Contents\"/></guide></package>"));
|
||||
|
||||
CFile oFile;
|
||||
oFile.CreateFile(pFormat->m_oTempManager.m_strTempDirectory + _T("\\content.opf"));
|
||||
CString strCont = oOpf.GetCString();
|
||||
oFile.WriteStringUTF8(strCont);
|
||||
oFile.CloseFile();
|
||||
|
||||
// toc.ncx
|
||||
CFile oFileTOC;
|
||||
oFileTOC.CreateFile(pFormat->m_oTempManager.m_strTempDirectory + _T("\\toc.ncx"));
|
||||
|
||||
CString str1 = _T("<?xml version=\"1.0\" encoding=\"utf-8\"?><ncx version=\"2005-1\" xmlns=\"http://www.daisy.org/z3986/2005/ncx/\">\
|
||||
<head><meta name=\"dtb:uid\" content=\"") + strGuid + _T("\"/><meta name=\"dtb:depth\" content=\"2\"/>\
|
||||
<meta content=\"Online Media Technologies Ltd.\" name=\"dtb:generator\"/><meta content=\"0\" name=\"dtb:totalPageCount\"/>\
|
||||
<meta content=\"0\" name=\"dtb:maxPageNumber\"/></head>\
|
||||
<docTitle><text>") + pFormat->m_oMeta.m_strName + _T("</text></docTitle><docAuthor><text>") + pFormat->m_oMeta.m_strAuthor + _T("</text></docAuthor><navMap>");
|
||||
oFileTOC.WriteStringUTF8(str1);
|
||||
m_oWriterTOC.WriteStringC(_T("</navMap></ncx>"));
|
||||
|
||||
CString str2 = m_oWriterTOC.GetCString();
|
||||
oFileTOC.WriteStringUTF8(str2);
|
||||
oFileTOC.CloseFile();
|
||||
|
||||
CFile oFileBook_toc;
|
||||
oFileBook_toc.CreateFile(pFormat->m_oTempManager.m_strTempDirectory + _T("\\book_toc.xhtml"));
|
||||
|
||||
CString str11 = _T("<?xml version='1.0' encoding='utf-8'?><html xmlns=\"http://www.w3.org/1999/xhtml\"><head>\
|
||||
<title>Table of Content</title><meta content=\"http://www.w3.org/1999/xhtml; charset=utf-8\" http-equiv=\"Content-Type\"/>\
|
||||
<link href=\"stylesheet.css\" type=\"text/css\" rel=\"stylesheet\"/><style type=\"text/css\"></style></head>\
|
||||
<body class=\"main\"><div id=\"maintoc\"><p class=\"heading1\"><span>Table of Contents</span></p>");
|
||||
|
||||
oFileBook_toc.WriteStringUTF8(str11);
|
||||
m_oWriterTOCReferenses.WriteStringC(_T("</div></body></html>"));
|
||||
|
||||
CString str22 = m_oWriterTOCReferenses.GetCString();
|
||||
oFileBook_toc.WriteStringUTF8(str22);
|
||||
oFileBook_toc.CloseFile();
|
||||
}
|
||||
|
||||
AVSINLINE void CheckSplitHtml()
|
||||
{
|
||||
if (m_oWriter.GetCurSize() > MAXHTMLSIZE)
|
||||
DumpCurrentHtml(m_pFormat);
|
||||
}
|
||||
|
||||
AVSINLINE void WriteImage(NSEBook::CEbookGraphicObject* pImage)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<div style=\"text-align:center;\"><img class=\"image_block\" src=\"media/image%d.%s\" alt=\"\"/></div>"), pImage->m_oInfo.m_lID,
|
||||
(NSCommon::itJPG == pImage->m_oInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
|
||||
if (pImage->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<div class=\"bookpagebreak\"/>"));
|
||||
}
|
||||
|
||||
CheckSplitHtml();
|
||||
}
|
||||
AVSINLINE void WriteParagraph(NSEBook::CEbookParagraph* pParagraph)
|
||||
{
|
||||
//pParagraph->CheckShadows();
|
||||
|
||||
if (1 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading1\">"));
|
||||
else if (2 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading2\">"));
|
||||
else
|
||||
{
|
||||
if (0 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\">"));
|
||||
}
|
||||
else if (1 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\" style=\"text-align:center;\">"));
|
||||
}
|
||||
else if (2 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\" style=\"text-align:right;\">"));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\">"));
|
||||
}
|
||||
}
|
||||
|
||||
NSEBook::CEbookParagraph::CSpan* pSpan = NULL;
|
||||
|
||||
POSITION posLine = pParagraph->m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CLine& oLine = pParagraph->m_arLines.GetNext(posLine);
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (NULL == pSpan)
|
||||
pSpan = &oSpan;
|
||||
else if (oSpan.m_oText.IsEqualLast(pSpan->m_oText, ((pSpan->m_dX + pSpan->m_dWidthSpan - oSpan.m_dX) > 1) ? TRUE : FALSE) && (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD>!
|
||||
continue;
|
||||
}
|
||||
else if (pSpan->m_oFont.IsEqual(&oSpan.m_oFont) && pSpan->m_oBrush.IsEqual(&oSpan.m_oBrush)
|
||||
&& (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
pSpan->m_oText += oSpan.m_oText;
|
||||
double mem = oSpan.m_dX + oSpan.m_dWidthSpan - pSpan->m_dX;
|
||||
if (mem > pSpan->m_dWidthSpan)
|
||||
pSpan->m_dWidthSpan = mem;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
pSpan = &oSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != pSpan)
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</p>"));
|
||||
|
||||
if (pParagraph->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<div class=\"bookpagebreak\"></div>"));
|
||||
//m_oWriter.WriteStringC(_T("<p style=\"page-break-after:always\"/>"));
|
||||
}
|
||||
|
||||
CheckSplitHtml();
|
||||
}
|
||||
|
||||
AVSINLINE void WriteSpan(NSEBook::CEbookParagraph::CSpan* pSpan)
|
||||
{
|
||||
if (-1 != pSpan->m_oImageInfo.m_lID)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<img class=\"image_inline\" src=\"media/image%d.%s\" alt=\"\"/>"), pSpan->m_oImageInfo.m_lID,
|
||||
(NSCommon::itJPG == pSpan->m_oImageInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
return;
|
||||
}
|
||||
CString strStyle1 = _T("");
|
||||
CString strStyle2 = _T("");
|
||||
|
||||
if (m_bIsFontsEmbedded)
|
||||
{
|
||||
CString strName = pSpan->m_oFont.Name;
|
||||
strName.Replace(_T(" "), _T("_avs_space_"));
|
||||
|
||||
strStyle1 = (_T("<span style=\"font-family:") + strName + _T(";"));
|
||||
if (pSpan->m_oFont.Bold)
|
||||
strStyle1 += _T("font-weight:bold;");
|
||||
else
|
||||
strStyle1 += _T("font-weight:normal;");
|
||||
|
||||
if (pSpan->m_oFont.Italic)
|
||||
strStyle1 += _T("font-style:italic;\">");
|
||||
else
|
||||
strStyle1 += _T("font-style:normal;\">");
|
||||
|
||||
strStyle2 = _T("</span>");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pSpan->m_oFont.Bold)
|
||||
{
|
||||
strStyle1 += _T("<b>");
|
||||
strStyle2 += _T("</b>");
|
||||
}
|
||||
if (pSpan->m_oFont.Italic)
|
||||
{
|
||||
strStyle1 += _T("<i>");
|
||||
strStyle2 = (_T("</i>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_oFont.Underline != 0)
|
||||
{
|
||||
strStyle1 += _T("<u>");
|
||||
strStyle2 = (_T("</u>") + strStyle2);
|
||||
}
|
||||
}
|
||||
|
||||
if (pSpan->m_dBaselineOffset < 0)
|
||||
{
|
||||
strStyle1 += _T("<sub>");
|
||||
strStyle2 = (_T("</sub>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_dBaselineOffset > 0)
|
||||
{
|
||||
strStyle1 += _T("<sup>");
|
||||
strStyle2 = (_T("</sup>") + strStyle2);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(strStyle1);
|
||||
m_oWriter.WriteTextXML(pSpan->m_oText);
|
||||
m_oWriter.WriteStringC(strStyle2);
|
||||
}
|
||||
AVSINLINE void WriteTable(NSEBook::CEbookTable* pTable)
|
||||
{
|
||||
m_oWriter.WriteString(pTable->m_strTableXml);
|
||||
if (pTable->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<div class=\"bookpagebreak\"/>"));
|
||||
}
|
||||
CheckSplitHtml();
|
||||
}
|
||||
AVSINLINE void WriteNumbering(NSEBook::CEbookNumbering* pNumbering)
|
||||
{
|
||||
CheckSplitHtml();
|
||||
}
|
||||
};
|
||||
}
|
||||
312
AVSEBOOKWriter/Writers/Writer_Fb2.h
Normal file
312
AVSEBOOKWriter/Writers/Writer_Fb2.h
Normal file
@ -0,0 +1,312 @@
|
||||
#pragma once
|
||||
#include "Writer.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CWriter_Fb2
|
||||
{
|
||||
public:
|
||||
NSCommon::CStringWriter m_oWriter;
|
||||
|
||||
public:
|
||||
void CreateDocument(CWriter* pWriter)
|
||||
{
|
||||
m_oWriter.ClearNoAttack();
|
||||
|
||||
CFormat* pFormat = &pWriter->m_oFormat;
|
||||
|
||||
m_oWriter.WriteStringC(_T("<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
|
||||
m_oWriter.WriteStringC(_T("<FictionBook xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.gribuser.ru/xml/fictionbook/2.0\">"));
|
||||
|
||||
m_oWriter.WriteStringC(_T("<description><title-info>"));
|
||||
m_oWriter.WriteString(_T("<author><first-name></first-name><last-name>") + pFormat->m_oMeta.m_strAuthor + _T("</last-name></author>"));
|
||||
m_oWriter.WriteString(_T("<book-title>") + pFormat->m_oMeta.m_strName + _T("</book-title>"));
|
||||
m_oWriter.WriteString(_T("<lang>") + pFormat->m_oMeta.m_strLanguage + _T("</lang>"));
|
||||
|
||||
if (pWriter->m_bIsSaveCover)
|
||||
{
|
||||
CString strCover = _T("#image1.jpg");
|
||||
if (0 != pWriter->m_oFormat.m_oImageManager.m_listImages.GetCount())
|
||||
{
|
||||
if (NSCommon::itPNG == pWriter->m_oFormat.m_oImageManager.m_listImages.GetHead().m_eType)
|
||||
strCover = _T("#image1.png");
|
||||
}
|
||||
m_oWriter.WriteString(_T("<coverpage><image xlink:href=\"") + strCover + _T("\"/></coverpage>"));
|
||||
}
|
||||
|
||||
if (0 != pFormat->m_oMeta.m_listAnnotation.GetCount())
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<annotation>"));
|
||||
|
||||
POSITION pos = pFormat->m_oMeta.m_listAnnotation.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = pFormat->m_oMeta.m_listAnnotation.GetNext(pos);
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case IEbookItem::ebitParagraph:
|
||||
{
|
||||
WriteParagraph((CEbookParagraph*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitTable:
|
||||
{
|
||||
WriteTable((CEbookTable*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitGraphic:
|
||||
{
|
||||
WriteImage((CEbookGraphicObject*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitNumbering:
|
||||
{
|
||||
WriteNumbering((CEbookNumbering*)pItem);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</annotation>"));
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</title-info>"));
|
||||
|
||||
m_oWriter.WriteStringC(_T("<document-info><author><first-name></first-name><last-name></last-name></author><program-used>Online Media Technologies Ltd.</program-used><date value=\"2011-07-26\">26.07.2011</date><id>"));
|
||||
GUID guid;
|
||||
CoCreateGuid(&guid);
|
||||
CString strGuid = _T("");
|
||||
strGuid.Format(_T("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"), guid.Data1, guid.Data2, guid.Data3,
|
||||
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
||||
m_oWriter.WriteString(strGuid);
|
||||
m_oWriter.WriteStringC(_T("</id><version>1.0</version></document-info>"));
|
||||
|
||||
m_oWriter.WriteString(_T("<publish-info><publisher>") + pFormat->m_oMeta.m_strPublisher + _T("</publisher></publish-info></description>"));
|
||||
|
||||
m_oWriter.WriteString(_T("<body>"));
|
||||
|
||||
POSITION posSect = pFormat->m_listSections.GetHeadPosition();
|
||||
while (NULL != posSect)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<section>"));
|
||||
CSection& oSection = pFormat->m_listSections.GetNext(posSect);
|
||||
|
||||
POSITION pos = oSection.m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = oSection.m_arItems.GetNext(pos);
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case IEbookItem::ebitParagraph:
|
||||
{
|
||||
WriteParagraph((CEbookParagraph*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitTable:
|
||||
{
|
||||
WriteTable((CEbookTable*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitGraphic:
|
||||
{
|
||||
WriteImage((CEbookGraphicObject*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitNumbering:
|
||||
{
|
||||
WriteNumbering((CEbookNumbering*)pItem);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_oWriter.WriteStringC(_T("</section>"));
|
||||
}
|
||||
|
||||
m_oWriter.WriteString(_T("</body>"));
|
||||
}
|
||||
void CloseFile(CString strDstFile, CWriter* pWriter)
|
||||
{
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strDstFile);
|
||||
|
||||
CString strData = m_oWriter.GetCString();
|
||||
oFile.WriteStringUTF8(strData);
|
||||
|
||||
m_oWriter.Clear();
|
||||
|
||||
POSITION pos = pWriter->m_oFormat.m_oImageManager.m_mapImagesFile.GetStartPosition();
|
||||
CString strMedia = pWriter->m_oFormat.m_oTempManager.m_strTempImagesDirectory;
|
||||
while (NULL != pos)
|
||||
{
|
||||
CImageInfo& info = pWriter->m_oFormat.m_oImageManager.m_mapImagesFile.GetNextValue(pos);
|
||||
WriteImageToFile(oFile, info, strMedia);
|
||||
}
|
||||
pos = pWriter->m_oFormat.m_oImageManager.m_mapImageData.GetStartPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CImageInfo& info = pWriter->m_oFormat.m_oImageManager.m_mapImageData.GetNextValue(pos);
|
||||
WriteImageToFile(oFile, info, strMedia);
|
||||
}
|
||||
|
||||
CString strEnd = _T("</FictionBook>");
|
||||
oFile.WriteStringUTF8(strEnd);
|
||||
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
void WriteImageToFile(CFile& oFile, CImageInfo& info, CString& strMedia)
|
||||
{
|
||||
CFile oImageFile;
|
||||
oImageFile.OpenFile(info.GetPath(strMedia));
|
||||
int nInputLen = (int)oImageFile.GetFileSize();
|
||||
BYTE* pData = new BYTE[nInputLen];
|
||||
oImageFile.ReadFile(pData, nInputLen);
|
||||
|
||||
int nOutputLen = Base64EncodeGetRequiredLength(nInputLen);
|
||||
BYTE* pOutput = new BYTE[nOutputLen];
|
||||
Base64Encode(pData, nInputLen, (LPSTR)pOutput, &nOutputLen);
|
||||
|
||||
CString strBinary = _T("");
|
||||
if (itJPG == info.m_eType)
|
||||
strBinary.Format(_T("<binary content-type=\"image/jpg\" id=\"image%d.jpg\">"), info.m_lID);
|
||||
else
|
||||
strBinary.Format(_T("<binary content-type=\"image/png\" id=\"image%d.png\">"), info.m_lID);
|
||||
|
||||
oFile.WriteStringUTF8(strBinary);
|
||||
oFile.WriteFile((void*)pOutput, nOutputLen);
|
||||
CString strBinaryEnd = _T("</binary>");
|
||||
oFile.WriteStringUTF8(strBinaryEnd);
|
||||
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
RELEASEARRAYOBJECTS(pOutput);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
AVSINLINE void WriteImage(NSEBook::CEbookGraphicObject* pImage)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<image xlink:href=\"#image%d.%s\"/>"), pImage->m_oInfo.m_lID,
|
||||
(NSCommon::itJPG == pImage->m_oInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
}
|
||||
AVSINLINE void WriteParagraph(NSEBook::CEbookParagraph* pParagraph)
|
||||
{
|
||||
//pParagraph->CheckShadows();
|
||||
|
||||
if (1 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<title>"));
|
||||
else if (2 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<subtitle>"));
|
||||
|
||||
m_oWriter.WriteStringC(_T("<p>"));
|
||||
NSEBook::CEbookParagraph::CSpan* pSpan = NULL;
|
||||
|
||||
POSITION posLine = pParagraph->m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CLine& oLine = pParagraph->m_arLines.GetNext(posLine);
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (NULL == pSpan)
|
||||
pSpan = &oSpan;
|
||||
else if (oSpan.m_oText.IsEqualLast(pSpan->m_oText, ((pSpan->m_dX + pSpan->m_dWidthSpan - oSpan.m_dX) > 1) ? TRUE : FALSE) && (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD>!
|
||||
continue;
|
||||
}
|
||||
else if (pSpan->m_oFont.IsEqual(&oSpan.m_oFont) && pSpan->m_oBrush.IsEqual(&oSpan.m_oBrush)
|
||||
&& (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
pSpan->m_oText += oSpan.m_oText;
|
||||
double mem = oSpan.m_dX + oSpan.m_dWidthSpan - pSpan->m_dX;
|
||||
if (mem > pSpan->m_dWidthSpan)
|
||||
pSpan->m_dWidthSpan = mem;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
pSpan = &oSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != pSpan)
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</p>"));
|
||||
|
||||
if (1 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("</title>"));
|
||||
else if (2 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("</subtitle>"));
|
||||
}
|
||||
|
||||
AVSINLINE void WriteSpan(NSEBook::CEbookParagraph::CSpan* pSpan)
|
||||
{
|
||||
if (-1 != pSpan->m_oImageInfo.m_lID)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<image xlink:href=\"#image%d.%s\"/>"), pSpan->m_oImageInfo.m_lID,
|
||||
(NSCommon::itJPG == pSpan->m_oImageInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
return;
|
||||
}
|
||||
CString strStyle1 = _T("");
|
||||
CString strStyle2 = _T("");
|
||||
|
||||
if (pSpan->m_oFont.Bold)
|
||||
{
|
||||
strStyle1 += _T("<strong>");
|
||||
strStyle2 += _T("</strong>");
|
||||
}
|
||||
if (pSpan->m_oFont.Italic)
|
||||
{
|
||||
strStyle1 += _T("<emphasis>");
|
||||
strStyle2 = (_T("</emphasis>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_oFont.Strikeout != 0)
|
||||
{
|
||||
strStyle1 += _T("<strikethrough>");
|
||||
strStyle2 = (_T("</strikethrough>") + strStyle2);
|
||||
}
|
||||
|
||||
if (pSpan->m_dBaselineOffset < 0)
|
||||
{
|
||||
strStyle1 += _T("<sub>");
|
||||
strStyle2 = (_T("</sub>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_dBaselineOffset > 0)
|
||||
{
|
||||
strStyle1 += _T("<sup>");
|
||||
strStyle2 = (_T("</sup>") + strStyle2);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(strStyle1);
|
||||
m_oWriter.WriteTextXML(pSpan->m_oText);
|
||||
m_oWriter.WriteStringC(strStyle2);
|
||||
}
|
||||
AVSINLINE void WriteTable(NSEBook::CEbookTable* pTable)
|
||||
{
|
||||
m_oWriter.WriteString(pTable->m_strTableXml);
|
||||
}
|
||||
AVSINLINE void WriteNumbering(NSEBook::CEbookNumbering* pNumbering)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
841
AVSEBOOKWriter/Writers/Writer_Mobi.h
Normal file
841
AVSEBOOKWriter/Writers/Writer_Mobi.h
Normal file
@ -0,0 +1,841 @@
|
||||
#pragma once
|
||||
#include "Writer.h"
|
||||
#include "../MOBIFormat/MobiReader.h"
|
||||
|
||||
#define FCIS_FLIS TRUE
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
#define TEXT_REC_LEN 4096
|
||||
class CWriter_Mobi
|
||||
{
|
||||
public:
|
||||
class CRecord
|
||||
{
|
||||
public:
|
||||
BYTE* m_pData;
|
||||
LONG m_lLen;
|
||||
|
||||
public:
|
||||
CRecord()
|
||||
{
|
||||
m_pData = NULL;
|
||||
m_lLen = 0;
|
||||
}
|
||||
~CRecord()
|
||||
{
|
||||
RELEASEARRAYOBJECTS(m_pData);
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
NSCommon::CStringWriter m_oWriter;
|
||||
bool m_bIsCompression;
|
||||
|
||||
CAtlList<CRecord*> m_arRecords;
|
||||
LONG m_lTextRecords;
|
||||
LONG m_lImageRecords;
|
||||
|
||||
CFormat* m_pFormat;
|
||||
bool m_bIsCover;
|
||||
bool m_bIsAdditionalTextRec;
|
||||
|
||||
public:
|
||||
CWriter_Mobi() : m_arRecords()
|
||||
{
|
||||
m_bIsCompression = true;
|
||||
}
|
||||
~CWriter_Mobi()
|
||||
{
|
||||
POSITION pos = m_arRecords.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CRecord* pRecord = m_arRecords.GetNext(pos);
|
||||
RELEASEOBJECT(pRecord);
|
||||
}
|
||||
m_arRecords.RemoveAll();
|
||||
}
|
||||
public:
|
||||
void CreateDocument(CWriter* pWriter)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> writer
|
||||
CString str1 = _T("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/><guide></guide>\n\
|
||||
<style type=\"text/css\">\n\
|
||||
.heading1 { text-align: center; font-weight: bold; font-size: 2em; }\n\
|
||||
.heading2 { text-align: center; font-weight: bold; font-size: 1.5em; }n\
|
||||
.heading0 { text-indent: 2em; text-align: justify; font-size: 1em; }\n\
|
||||
.image_inline { vertical-align: baseline; }\n\
|
||||
.image_block { vertical-align: baseline; }\n\
|
||||
.main { display: block; font-size: 1em; margin-bottom: 0; margin-left: 5pt; margin-right: 5pt; margin-top: 0; padding-left: 0; padding-right: 0; text-align: justify }\n\
|
||||
.hyper { text-decoration: underline; }\n\
|
||||
</style></head><body class=\"main\">");
|
||||
m_oWriter.WriteStringC(str1);
|
||||
|
||||
/*CString str1 = _T("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/><guide></guide>\n\
|
||||
</head><body>");
|
||||
m_oWriter.WriteStringC(str1);*/
|
||||
|
||||
m_bIsCover = pWriter->m_bIsSaveCover;
|
||||
|
||||
m_pFormat = &pWriter->m_oFormat;
|
||||
POSITION posSect = m_pFormat->m_listSections.GetHeadPosition();
|
||||
while (NULL != posSect)
|
||||
{
|
||||
CSection& oSection = m_pFormat->m_listSections.GetNext(posSect);
|
||||
|
||||
m_oWriter.WriteStringC(_T("<div><a/>"));
|
||||
|
||||
POSITION pos = oSection.m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = oSection.m_arItems.GetNext(pos);
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case IEbookItem::ebitParagraph:
|
||||
{
|
||||
WriteParagraph((CEbookParagraph*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitTable:
|
||||
{
|
||||
WriteTable((CEbookTable*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitGraphic:
|
||||
{
|
||||
WriteImage((CEbookGraphicObject*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitNumbering:
|
||||
{
|
||||
WriteNumbering((CEbookNumbering*)pItem);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != posSect)
|
||||
m_oWriter.WriteStringC(_T("<mbp:pagebreak/></div>"));
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</body></html>"));
|
||||
|
||||
#ifdef _DEBUG
|
||||
CString strXml = m_oWriter.GetCString();
|
||||
CDirectory::SaveToFile(_T("C:\\debug_mobi.html"), strXml);
|
||||
#endif
|
||||
}
|
||||
void CloseFile(CString strDstFile, CWriter* pWriter)
|
||||
{
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strDstFile);
|
||||
|
||||
// -------------- DEBUG ------------------------------
|
||||
if (FALSE)
|
||||
{
|
||||
CFile oFileD;
|
||||
oFileD.OpenFile(_T("C:\\images.html"));
|
||||
CString strH = oFileD.ReadStringFromUTF8((DWORD)oFileD.GetFileSize());
|
||||
oFileD.CloseFile();
|
||||
m_oWriter.WriteString(strH);
|
||||
}
|
||||
// ---------------------------------------------------
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
CString strXml = m_oWriter.GetCString();
|
||||
int nLength = strXml.GetLength();
|
||||
|
||||
CStringA saStr;
|
||||
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, strXml.GetBuffer(), nLength + 1, saStr.GetBuffer(nLength*3 + 1), nLength*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
|
||||
LONG lSrcLen = saStr.GetLength();
|
||||
BYTE* pSrcBuffer = (BYTE*)saStr.GetBuffer();
|
||||
LONG lSrcCount = saStr.GetLength();
|
||||
|
||||
m_lImageRecords = (LONG)pWriter->m_oFormat.m_oImageManager.m_listImages.GetCount();
|
||||
|
||||
GenerateRecords(pWriter, pSrcBuffer, lSrcLen);
|
||||
GenerateRecord0(&pWriter->m_oFormat, lSrcLen);
|
||||
|
||||
CFormat* pFormat = &pWriter->m_oFormat;
|
||||
|
||||
LONG lRecCount = m_lTextRecords + m_lImageRecords + 1 + 1;
|
||||
if (FCIS_FLIS)
|
||||
lRecCount += 2;
|
||||
|
||||
NSMobi::CStream oStream;
|
||||
oStream.CreateFromBuffer(1000 + lRecCount * 8);
|
||||
|
||||
NSMobi::CMobiReader::CPDBHeader oHeader1;
|
||||
oHeader1.WriteToStream(&oStream, pFormat->m_oMeta.m_strName, lRecCount);
|
||||
|
||||
POSITION posRec = m_arRecords.GetHeadPosition();
|
||||
DWORD dwOffset = (DWORD)oStream.GetPosition() + lRecCount * 8;
|
||||
LONG i = 0;
|
||||
while (NULL != posRec)
|
||||
{
|
||||
CRecord* pRecord = m_arRecords.GetNext(posRec);
|
||||
|
||||
oStream.WriteDWORD(dwOffset);
|
||||
|
||||
DWORD dwFlag = (DWORD)(2 * i);
|
||||
dwFlag &= 0x00FFFFFF;
|
||||
|
||||
oStream.WriteDWORD(dwFlag);
|
||||
|
||||
dwOffset += (DWORD)pRecord->m_lLen;
|
||||
++i;
|
||||
}
|
||||
|
||||
oStream.DumpToFile(oFile);
|
||||
|
||||
posRec = m_arRecords.GetHeadPosition();
|
||||
while (NULL != posRec)
|
||||
{
|
||||
CRecord* pRecord = m_arRecords.GetNext(posRec);
|
||||
oFile.WriteFile((void*)pRecord->m_pData, pRecord->m_lLen);
|
||||
}
|
||||
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void GenerateRecords(CWriter* pWriter, BYTE* pSrcBuffer, LONG lSrcLen)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE* inputStart = pSrcBuffer;
|
||||
LONG lCurrentLenTail = lSrcLen;
|
||||
|
||||
LONG lDataSize = 0;
|
||||
while (lCurrentLenTail > 0)
|
||||
{
|
||||
BYTE* current = inputStart;
|
||||
|
||||
LONG lCurrentRecLen = 0;
|
||||
while (lCurrentLenTail > 0)
|
||||
{
|
||||
if (0x00 == (0x80 & *current))
|
||||
{
|
||||
++current;
|
||||
++lCurrentRecLen;
|
||||
|
||||
--lCurrentLenTail;
|
||||
}
|
||||
else if (0x00 == (0x20 & *current))
|
||||
{
|
||||
current += 2;
|
||||
lCurrentRecLen += 2;
|
||||
|
||||
lCurrentLenTail -= 2;
|
||||
}
|
||||
else if (0x00 == (0x10 & *current))
|
||||
{
|
||||
current += 3;
|
||||
lCurrentRecLen += 3;
|
||||
|
||||
lCurrentLenTail -= 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
++current;
|
||||
++lCurrentRecLen;
|
||||
|
||||
--lCurrentLenTail;
|
||||
}
|
||||
|
||||
if (lCurrentRecLen >= TEXT_REC_LEN)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lCurrentRecLen == TEXT_REC_LEN)
|
||||
{
|
||||
if (!m_bIsCompression)
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_pData = new BYTE[TEXT_REC_LEN];
|
||||
pRecord->m_lLen = TEXT_REC_LEN;
|
||||
memcpy(pRecord->m_pData, inputStart, TEXT_REC_LEN);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
NSMobi::CTextDecoder::PalmEncode(inputStart, TEXT_REC_LEN, pRecord->m_pData, pRecord->m_lLen, TEXT_REC_LEN);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
}
|
||||
else if (lCurrentRecLen > TEXT_REC_LEN)
|
||||
{
|
||||
if (!m_bIsCompression)
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_pData = new BYTE[lCurrentRecLen];
|
||||
pRecord->m_lLen = lCurrentRecLen;
|
||||
memcpy(pRecord->m_pData, inputStart, lCurrentRecLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
NSMobi::CTextDecoder::PalmEncode(inputStart, TEXT_REC_LEN, pRecord->m_pData, pRecord->m_lLen, lCurrentRecLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FALSE)
|
||||
{
|
||||
BYTE* pData = new BYTE[TEXT_REC_LEN];
|
||||
memset(pData, 32, TEXT_REC_LEN);
|
||||
memcpy(pData, inputStart, lCurrentRecLen);
|
||||
|
||||
if (!m_bIsCompression)
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_pData = pData;
|
||||
pRecord->m_lLen = TEXT_REC_LEN;
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
NSMobi::CTextDecoder::PalmEncode(pData, lCurrentRecLen, pRecord->m_pData, pRecord->m_lLen, TEXT_REC_LEN);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_bIsCompression)
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_pData = new BYTE[lCurrentRecLen];
|
||||
pRecord->m_lLen = lCurrentRecLen;
|
||||
memcpy(pRecord->m_pData, inputStart, lCurrentRecLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
NSMobi::CTextDecoder::PalmEncode(inputStart, lCurrentRecLen, pRecord->m_pData, pRecord->m_lLen, lCurrentRecLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inputStart = current;
|
||||
}
|
||||
|
||||
m_bIsAdditionalTextRec = false;
|
||||
|
||||
m_lTextRecords = (LONG)m_arRecords.GetCount();
|
||||
|
||||
/*
|
||||
LONG lModule4 = lDataSize % 4;
|
||||
if (0 != lModule4)
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_pData = new BYTE[pRecord->m_lLen];
|
||||
memset(pRecord->m_pData, 0, pRecord->m_lLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
m_bIsAdditionalTextRec = true;
|
||||
}
|
||||
*/
|
||||
|
||||
NSCommon::CImageManager* pManager = &pWriter->m_oFormat.m_oImageManager;
|
||||
CString strMediaPath = pWriter->m_oFormat.m_oTempManager.m_strTempImagesDirectory;
|
||||
POSITION posImage = pManager->m_listImages.GetHeadPosition();
|
||||
while (NULL != posImage)
|
||||
{
|
||||
NSCommon::CImageInfo& info = pManager->m_listImages.GetNext(posImage);
|
||||
|
||||
CFile oImageFile;
|
||||
oImageFile.OpenFile(info.GetPath(strMediaPath));
|
||||
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_lLen = (LONG)oImageFile.GetFileSize();
|
||||
pRecord->m_pData = new BYTE[pRecord->m_lLen];
|
||||
oImageFile.ReadFile(pRecord->m_pData, (DWORD)pRecord->m_lLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
oImageFile.CloseFile();
|
||||
}
|
||||
|
||||
GenerateEndRecords(lSrcLen);
|
||||
}
|
||||
|
||||
void GenerateRecord0(NSEBook::CFormat* pFormat, LONG lSrcTextLen)
|
||||
{
|
||||
LONG lRecCount = m_lTextRecords + m_lImageRecords + 1 + 1;
|
||||
if (FCIS_FLIS)
|
||||
lRecCount += 2;
|
||||
|
||||
NSMobi::CStream oStream;
|
||||
oStream.CreateFromBuffer(1024 * 1024); // 1mb
|
||||
|
||||
// mobiheader
|
||||
if (m_bIsCompression)
|
||||
oStream.WriteUShort(2);
|
||||
else
|
||||
oStream.WriteUShort(1);
|
||||
|
||||
oStream.WriteUShort(0);
|
||||
oStream.WriteLong(lSrcTextLen);
|
||||
oStream.WriteUShort((USHORT)(m_lTextRecords));
|
||||
oStream.WriteUShort(4096);
|
||||
oStream.WriteUShort(0);
|
||||
oStream.WriteUShort(0);
|
||||
|
||||
DWORD uid = rand();
|
||||
|
||||
oStream.WriteCStringA("MOBI");
|
||||
oStream.WriteDWORD(0xE8);
|
||||
oStream.WriteDWORD(0x02);
|
||||
oStream.WriteDWORD(65001);
|
||||
oStream.WriteDWORD(uid);
|
||||
oStream.WriteDWORD(0x06);
|
||||
|
||||
oStream.WriteSet(0xFF, 8);
|
||||
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
|
||||
oStream.WriteSet(0xFF, 28);
|
||||
|
||||
NSMobi::CStream oStreamEXTH;
|
||||
NSMobi::CStream oStreamTITLE;
|
||||
oStreamEXTH.CreateFromBuffer(1024 * 5);
|
||||
oStreamTITLE.CreateFromBuffer(1024 * 5);
|
||||
|
||||
GenerateEXTH(oStreamEXTH, pFormat);
|
||||
GenerateTITLE(oStreamTITLE, pFormat);
|
||||
|
||||
oStream.WriteDWORD((DWORD)(m_lTextRecords + 1));
|
||||
oStream.WriteDWORD((DWORD)(0xe8 + 16 + oStreamEXTH.GetPosition()));
|
||||
oStream.WriteDWORD((DWORD)oStreamTITLE.GetPosition());
|
||||
|
||||
oStream.WriteDWORD(0);
|
||||
|
||||
oStream.WriteSet(0, 8);
|
||||
|
||||
oStream.WriteDWORD(6);
|
||||
|
||||
if (0 == m_lImageRecords)
|
||||
oStream.WriteDWORD(0);
|
||||
else
|
||||
oStream.WriteDWORD(m_lTextRecords + 1);
|
||||
|
||||
oStream.WriteSet(0, 16);
|
||||
|
||||
oStream.WriteDWORD(0x50);
|
||||
oStream.WriteSet(0, 32);
|
||||
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(0);
|
||||
oStream.WriteDWORD(0);
|
||||
|
||||
oStream.WriteSet(0, 12);
|
||||
oStream.WriteUShort(1);
|
||||
oStream.WriteUShort((USHORT)(lRecCount - 1));
|
||||
|
||||
oStream.WriteByte(0);
|
||||
oStream.WriteByte(0);
|
||||
oStream.WriteByte(0);
|
||||
oStream.WriteByte(1);
|
||||
|
||||
if (FCIS_FLIS)
|
||||
{
|
||||
oStream.WriteDWORD((DWORD)(m_lImageRecords + m_lTextRecords + 2));
|
||||
oStream.WriteDWORD(1);
|
||||
oStream.WriteDWORD((DWORD)(m_lImageRecords + m_lTextRecords + 1));
|
||||
oStream.WriteDWORD(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(1);
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(1);
|
||||
}
|
||||
|
||||
oStream.WriteSet(0, 8);
|
||||
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(0x00);
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
|
||||
oStream.WriteDWORD(1);
|
||||
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
|
||||
oStream.Write(&oStreamEXTH);
|
||||
oStream.Write(&oStreamTITLE);
|
||||
|
||||
if (TRUE)
|
||||
{
|
||||
//oStream.WriteSet(0, 1024 * 8);
|
||||
oStream.WriteSet(0, 8);
|
||||
}
|
||||
|
||||
int nPos = oStream.GetPosition();
|
||||
int mod = nPos % 4;
|
||||
if (0 != mod)
|
||||
oStream.WriteSet(0, 4 - mod);
|
||||
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_lLen = oStream.GetPosition();
|
||||
pRecord->m_pData = new BYTE[pRecord->m_lLen];
|
||||
memcpy(pRecord->m_pData, oStream.GetData(), pRecord->m_lLen);
|
||||
m_arRecords.AddHead(pRecord);
|
||||
}
|
||||
|
||||
void GenerateEndRecords(LONG lTextLength)
|
||||
{
|
||||
if (FCIS_FLIS)
|
||||
{
|
||||
NSMobi::CStream oStream;
|
||||
oStream.FromBuffer(new BYTE[100], 100);
|
||||
|
||||
oStream.WriteCStringA("FLIS");
|
||||
oStream.WriteDWORD(0x08);
|
||||
oStream.WriteUShort(0x41);
|
||||
oStream.WriteDWORD(0x00);
|
||||
oStream.WriteDWORD(0xFFFF);
|
||||
oStream.WriteUShort(0xFFFF);
|
||||
oStream.WriteDWORD(0x00010003);
|
||||
oStream.WriteDWORD(0x03);
|
||||
oStream.WriteDWORD(0x01);
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_lLen = (LONG)oStream.GetPosition();
|
||||
pRecord->m_pData = new BYTE[pRecord->m_lLen];
|
||||
memcpy(pRecord->m_pData, oStream.GetData(), pRecord->m_lLen);
|
||||
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
oStream.Seek(0);
|
||||
|
||||
oStream.WriteCStringA("FCIS");
|
||||
oStream.WriteDWORD(0x14);
|
||||
oStream.WriteDWORD(0x10);
|
||||
oStream.WriteDWORD(0x01);
|
||||
oStream.WriteDWORD(0x00);
|
||||
oStream.WriteDWORD((DWORD)lTextLength);
|
||||
oStream.WriteDWORD(0x00);
|
||||
oStream.WriteDWORD(0x20);
|
||||
oStream.WriteDWORD(0x08);
|
||||
oStream.WriteDWORD(0x00010001);
|
||||
oStream.WriteDWORD(0x00);
|
||||
|
||||
CRecord* pRecord2 = new CRecord();
|
||||
pRecord2->m_lLen = (LONG)oStream.GetPosition();
|
||||
pRecord2->m_pData = new BYTE[pRecord2->m_lLen];
|
||||
memcpy(pRecord2->m_pData, oStream.GetData(), pRecord2->m_lLen);
|
||||
|
||||
m_arRecords.AddTail(pRecord2);
|
||||
|
||||
CRecord* pRecordEnd = new CRecord();
|
||||
pRecordEnd->m_lLen = 4;
|
||||
pRecordEnd->m_pData = new BYTE[4];
|
||||
pRecordEnd->m_pData[0] = 0xE9;
|
||||
pRecordEnd->m_pData[0] = 0x8E;
|
||||
pRecordEnd->m_pData[0] = 0x0D;
|
||||
pRecordEnd->m_pData[0] = 0x0A;
|
||||
|
||||
m_arRecords.AddTail(pRecordEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecord* pRecordEnd = new CRecord();
|
||||
pRecordEnd->m_lLen = 4;
|
||||
pRecordEnd->m_pData = new BYTE[4];
|
||||
pRecordEnd->m_pData[0] = 0xE9;
|
||||
pRecordEnd->m_pData[0] = 0x8E;
|
||||
pRecordEnd->m_pData[0] = 0x0D;
|
||||
pRecordEnd->m_pData[0] = 0x0A;
|
||||
|
||||
m_arRecords.AddTail(pRecordEnd);
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateEXTH(NSMobi::CStream& oStream, NSEBook::CFormat* pFormat)
|
||||
{
|
||||
oStream.WriteCStringA("EXTH");
|
||||
|
||||
BYTE* pDataLen = oStream.GetCurrentData();
|
||||
oStream.WriteDWORD(0);
|
||||
oStream.WriteDWORD(0);
|
||||
|
||||
DWORD dwCountRecords = 0;
|
||||
if (_T("") != pFormat->m_oMeta.m_strAuthor)
|
||||
{
|
||||
CStringA strAuthor = ConverToUTF8(pFormat->m_oMeta.m_strAuthor);
|
||||
NSMobi::CMobiReader::CEXTHHeader::WriteRec(oStream, 100, strAuthor);
|
||||
++dwCountRecords;
|
||||
}
|
||||
if (_T("") != pFormat->m_oMeta.m_strCreatorProgram)
|
||||
{
|
||||
CStringA strAuthor = ConverToUTF8(pFormat->m_oMeta.m_strCreatorProgram);
|
||||
NSMobi::CMobiReader::CEXTHHeader::WriteRec(oStream, 108, strAuthor);
|
||||
++dwCountRecords;
|
||||
}
|
||||
if (_T("") != pFormat->m_oMeta.m_strPublisher)
|
||||
{
|
||||
CStringA strAuthor = ConverToUTF8(pFormat->m_oMeta.m_strPublisher);
|
||||
NSMobi::CMobiReader::CEXTHHeader::WriteRec(oStream, 101, strAuthor);
|
||||
++dwCountRecords;
|
||||
}
|
||||
if (m_bIsCover)
|
||||
{
|
||||
NSMobi::CMobiReader::CEXTHHeader::WriteRec(oStream, 201, (DWORD)0);
|
||||
++dwCountRecords;
|
||||
}
|
||||
if (0 != pFormat->m_oMeta.m_listAnnotation.GetCount())
|
||||
{
|
||||
CString strAnno = _T("");
|
||||
POSITION pos = pFormat->m_oMeta.m_listAnnotation.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
NSEBook::IEbookItem* pItem = pFormat->m_oMeta.m_listAnnotation.GetNext(pos);
|
||||
if (NSEBook::IEbookItem::ebitParagraph == pItem->m_eType)
|
||||
{
|
||||
strAnno += _T("<p>");
|
||||
strAnno += CorrectString2(((NSEBook::CEbookParagraph*)pItem)->GetAllText());
|
||||
strAnno += _T("</p>");
|
||||
}
|
||||
}
|
||||
|
||||
CStringA strAnnoA = ConverToUTF8(strAnno);
|
||||
NSMobi::CMobiReader::CEXTHHeader::WriteRec(oStream, 103, strAnnoA);
|
||||
++dwCountRecords;
|
||||
}
|
||||
|
||||
LONG lLen = oStream.GetPosition();
|
||||
LONG lPad = 4 - (lLen % 4);
|
||||
|
||||
DWORD dwSize1 = (DWORD)(lLen + 12);
|
||||
DWORD dwSize2 = dwCountRecords;
|
||||
|
||||
*pDataLen = (BYTE)(dwSize1 >> 24);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)(dwSize1 >> 16);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)(dwSize1 >> 8);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)dwSize1;
|
||||
++pDataLen;
|
||||
|
||||
*pDataLen = (BYTE)(dwSize2 >> 24);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)(dwSize2 >> 16);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)(dwSize2 >> 8);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)dwSize2;
|
||||
++pDataLen;
|
||||
|
||||
if (4 != lPad)
|
||||
oStream.WriteSet(0, lPad);
|
||||
}
|
||||
|
||||
void GenerateTITLE(NSMobi::CStream& oStream, NSEBook::CFormat* pFormat)
|
||||
{
|
||||
CStringA str = ConverToUTF8(pFormat->m_oMeta.m_strName);
|
||||
oStream.WriteCStringA(str);
|
||||
}
|
||||
|
||||
CStringA ConverToUTF8(CString& strXml)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
int nLength = strXml.GetLength();
|
||||
|
||||
CStringA saStr;
|
||||
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, strXml.GetBuffer(), nLength + 1, saStr.GetBuffer(nLength*3 + 1), nLength*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
|
||||
return saStr;
|
||||
}
|
||||
|
||||
/////////
|
||||
AVSINLINE void WriteImage(NSEBook::CEbookGraphicObject* pImage)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
LONG width = (LONG)(c_dpiBook * pImage->m_rcBounds.GetWidth() / c_dInchToMM);
|
||||
LONG height = (LONG)(c_dpiBook * pImage->m_rcBounds.GetHeight() / c_dInchToMM);
|
||||
strImage.Format(_T("<img recindex=\"%d\" align=\"baseline\" height=\"%d\" width=\"%d\" alt=\"\"/>"), pImage->m_oInfo.m_lID,
|
||||
height, width);
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
|
||||
if (pImage->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<mbp:pagebreak/>"));
|
||||
}
|
||||
}
|
||||
AVSINLINE void WriteParagraph(NSEBook::CEbookParagraph* pParagraph)
|
||||
{
|
||||
//pParagraph->CheckShadows();
|
||||
|
||||
if (1 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading1\">"));
|
||||
else if (2 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading2\">"));
|
||||
else
|
||||
{
|
||||
if (0 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\">"));
|
||||
}
|
||||
else if (1 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\" style=\"text-align:center;\">"));
|
||||
}
|
||||
else if (2 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\" style=\"text-align:right;\">"));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\">"));
|
||||
}
|
||||
}
|
||||
|
||||
NSEBook::CEbookParagraph::CSpan* pSpan = NULL;
|
||||
|
||||
POSITION posLine = pParagraph->m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CLine& oLine = pParagraph->m_arLines.GetNext(posLine);
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (NULL == pSpan)
|
||||
pSpan = &oSpan;
|
||||
else if (oSpan.m_oText.IsEqualLast(pSpan->m_oText, ((pSpan->m_dX + pSpan->m_dWidthSpan - oSpan.m_dX) > 1) ? TRUE : FALSE) && (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD>!
|
||||
continue;
|
||||
}
|
||||
else if (pSpan->m_oFont.IsEqual(&oSpan.m_oFont) && pSpan->m_oBrush.IsEqual(&oSpan.m_oBrush)
|
||||
&& (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
pSpan->m_oText += oSpan.m_oText;
|
||||
double mem = oSpan.m_dX + oSpan.m_dWidthSpan - pSpan->m_dX;
|
||||
if (mem > pSpan->m_dWidthSpan)
|
||||
pSpan->m_dWidthSpan = mem;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
pSpan = &oSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != pSpan)
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</p>"));
|
||||
|
||||
if (pParagraph->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<mbp:pagebreak/>"));
|
||||
}
|
||||
}
|
||||
|
||||
AVSINLINE void WriteSpan(NSEBook::CEbookParagraph::CSpan* pSpan)
|
||||
{
|
||||
if (-1 != pSpan->m_oImageInfo.m_lID)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
LONG width = (LONG)(c_dpiBook * pSpan->m_dImageWidth / c_dInchToMM);
|
||||
LONG height = (LONG)(c_dpiBook * pSpan->m_dImageHeight / c_dInchToMM);
|
||||
strImage.Format(_T("<img recindex=\"%d\" align=\"baseline\" height=\"%d\" width=\"%d\" alt=\"\"/>"), pSpan->m_oImageInfo.m_lID,
|
||||
height, width);
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
return;
|
||||
}
|
||||
CString strStyle1 = _T("");
|
||||
CString strStyle2 = _T("");
|
||||
|
||||
if (pSpan->m_oFont.Bold)
|
||||
{
|
||||
strStyle1 += _T("<b>");
|
||||
strStyle2 += _T("</b>");
|
||||
}
|
||||
if (pSpan->m_oFont.Italic)
|
||||
{
|
||||
strStyle1 += _T("<i>");
|
||||
strStyle2 = (_T("</i>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_oFont.Underline != 0)
|
||||
{
|
||||
strStyle1 += _T("<u>");
|
||||
strStyle2 = (_T("</u>") + strStyle2);
|
||||
}
|
||||
|
||||
if (pSpan->m_dBaselineOffset < 0)
|
||||
{
|
||||
strStyle1 += _T("<sub>");
|
||||
strStyle2 = (_T("</sub>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_dBaselineOffset > 0)
|
||||
{
|
||||
strStyle1 += _T("<sup>");
|
||||
strStyle2 = (_T("</sup>") + strStyle2);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(strStyle1);
|
||||
m_oWriter.WriteTextHTML(pSpan->m_oText);
|
||||
m_oWriter.WriteStringC(strStyle2);
|
||||
}
|
||||
AVSINLINE void WriteTable(NSEBook::CEbookTable* pTable)
|
||||
{
|
||||
m_oWriter.WriteString(pTable->m_strTableXml);
|
||||
|
||||
if (pTable->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<mbp:pagebreak/>"));
|
||||
}
|
||||
}
|
||||
AVSINLINE void WriteNumbering(NSEBook::CEbookNumbering* pNumbering)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
17
AVSEBOOKWriter/resource.h
Normal file
17
AVSEBOOKWriter/resource.h
Normal file
@ -0,0 +1,17 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by AVSEBOOKWriter.rc
|
||||
//
|
||||
#define IDS_PROJNAME 100
|
||||
#define IDR_AVSEBOOKWRITER 101
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 209
|
||||
#define _APS_NEXT_COMMAND_VALUE 32768
|
||||
#define _APS_NEXT_CONTROL_VALUE 201
|
||||
#define _APS_NEXT_SYMED_VALUE 102
|
||||
#endif
|
||||
#endif
|
||||
5
AVSEBOOKWriter/stdafx.cpp
Normal file
5
AVSEBOOKWriter/stdafx.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// AVSEBOOKWriter.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
56
AVSEBOOKWriter/stdafx.h
Normal file
56
AVSEBOOKWriter/stdafx.h
Normal file
@ -0,0 +1,56 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently,
|
||||
// but are changed infrequently
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef STRICT
|
||||
#define STRICT
|
||||
#endif
|
||||
|
||||
// Modify the following defines if you have to target a platform prior to the ones specified below.
|
||||
// Refer to MSDN for the latest info on corresponding values for different platforms.
|
||||
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
|
||||
#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
|
||||
#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 2000 or later.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
|
||||
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
|
||||
#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later.
|
||||
#endif
|
||||
|
||||
#define _ATL_APARTMENT_THREADED
|
||||
#define _ATL_NO_AUTOMATIC_NAMESPACE
|
||||
|
||||
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
|
||||
|
||||
// turns off ATL's hiding of some common and often safely ignored warning messages
|
||||
#define _ATL_ALL_WARNINGS
|
||||
|
||||
#include <atlbase.h>
|
||||
#include <atlcom.h>
|
||||
#include <atlwin.h>
|
||||
#include <atltypes.h>
|
||||
#include <atlctl.h>
|
||||
#include <atlhost.h>
|
||||
|
||||
using namespace ATL;
|
||||
|
||||
#define DOCX_RENDERER
|
||||
#define _USE_XMLLITE_READER_
|
||||
|
||||
#import "..\..\..\Redist\AVSGraphics.dll" named_guids raw_interfaces_only rename_namespace("AVSGraphics")
|
||||
#import "..\..\..\Redist\AVSMediaCore3.dll" named_guids raw_interfaces_only rename_namespace("MediaCore"), exclude("tagRECT")
|
||||
#import "..\..\..\Redist\AVSMediaFormatSettings3.dll" named_guids raw_interfaces_only rename_namespace("MediaFormat"), exclude("tagRECT")
|
||||
#import "..\..\..\Redist\AVSImageStudio3.dll" named_guids raw_interfaces_only rename_namespace("ImageStudio")
|
||||
#import "..\..\..\Redist\AVSOfficeStudio\AVSOfficeUtils.dll" named_guids rename_namespace("AVSOfficeUtils"), raw_interfaces_only
|
||||
|
||||
#import "..\..\..\Redist\AVSOfficeStudio\AVSOfficeHtmlFile.dll" raw_interfaces_only rename_namespace("OfficeHtmlFile")
|
||||
#import "..\..\..\Redist\AVSOfficeStudio\AVSOfficeTxtFile.dll" raw_interfaces_only rename_namespace("OfficeTxtFile")
|
||||
7
AVSEBOOKWriter/version.h
Normal file
7
AVSEBOOKWriter/version.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
//1
|
||||
//0
|
||||
//0
|
||||
//19
|
||||
#define INTVER 1,0,0,19
|
||||
#define STRVER "1,0,0,19\0"
|
||||
14
AVSEBOOKWriter2/AVSEBOOKWriter.cpp
Normal file
14
AVSEBOOKWriter2/AVSEBOOKWriter.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// AVSEBOOKWriter.cpp : Implementation of DLL Exports.
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "resource.h"
|
||||
|
||||
#include "EBOOKWriter.h"
|
||||
#include "MobiFormat/MobiFile.h"
|
||||
|
||||
// The module attribute causes DllMain, DllRegisterServer and DllUnregisterServer to be automatically implemented for you
|
||||
[ module(dll, uuid = "{218DB989-85F3-4512-8A6D-71A7211FBC5A}",
|
||||
name = "AVSEBOOKWriter",
|
||||
helpstring = "AVSEBOOKWriter 1.0 Type Library",
|
||||
resource_name = "IDR_AVSEBOOKWRITER") ];
|
||||
144
AVSEBOOKWriter2/AVSEBOOKWriter.rc
Normal file
144
AVSEBOOKWriter2/AVSEBOOKWriter.rc
Normal file
@ -0,0 +1,144 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
#include "version.h"
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE 9, 1
|
||||
#pragma code_page(1251)
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Document
|
||||
//
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""winres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION INTVER
|
||||
PRODUCTVERSION INTVER
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904B0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Online Media Technologies Ltd."
|
||||
VALUE "FileDescription", "AVSEBOOKWriter ActiveX DLL"
|
||||
VALUE "FileVersion", STRVER
|
||||
VALUE "LegalCopyright", "Online Media Technologies Ltd. Copyright (c) 2010"
|
||||
VALUE "InternalName", "AVSEBOOKWriter.dll"
|
||||
VALUE "OriginalFilename", "AVSEBOOKWriter.dll"
|
||||
VALUE "ProductName", "AVSEBOOKWriterActiveX DLL"
|
||||
VALUE "ProductVersion", STRVER
|
||||
VALUE "OLESelfRegister", ""
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0409, 0x04B0
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// REGISTRY
|
||||
//
|
||||
|
||||
IDR_AVSEBOOKWRITER REGISTRY "AVSEBOOKWriter.rgs"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_PROJNAME "AVSEBOOKWriter"
|
||||
END
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
11
AVSEBOOKWriter2/AVSEBOOKWriter.rgs
Normal file
11
AVSEBOOKWriter2/AVSEBOOKWriter.rgs
Normal file
@ -0,0 +1,11 @@
|
||||
HKCR
|
||||
{
|
||||
NoRemove AppID
|
||||
{
|
||||
'%APPID%' = s 'AVSEBOOKWriter'
|
||||
'AVSEBOOKWriter.DLL'
|
||||
{
|
||||
val AppID = s '%APPID%'
|
||||
}
|
||||
}
|
||||
}
|
||||
19
AVSEBOOKWriter2/AVSEBOOKWriter.sln
Normal file
19
AVSEBOOKWriter2/AVSEBOOKWriter.sln
Normal file
@ -0,0 +1,19 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual C++ Express 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AVSEBOOKWriter", "AVSEBOOKWriter.vcproj", "{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
787
AVSEBOOKWriter2/AVSEBOOKWriter.vcproj
Normal file
787
AVSEBOOKWriter2/AVSEBOOKWriter.vcproj
Normal file
@ -0,0 +1,787 @@
|
||||
<?xml version="1.0" encoding="windows-1251"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Name="AVSEBOOKWriter"
|
||||
ProjectGUID="{BAB70A60-2DA0-4149-B8FC-99D7007E9BDB}"
|
||||
RootNamespace="AVSEBOOKWriter"
|
||||
Keyword="AtlProj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="2"
|
||||
UseOfATL="1"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
CommandLine=""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
MkTypLibCompatible="false"
|
||||
TargetEnvironment="1"
|
||||
GenerateStublessProxies="true"
|
||||
TypeLibraryName="$(IntDir)/AVSEBOOKWriter.tlb"
|
||||
HeaderFileName="EBOOKWriter.h"
|
||||
DLLDataFileName=""
|
||||
InterfaceIdentifierFileName="AVSEBOOKWriter_i.c"
|
||||
ProxyFileName="AVSEBOOKWriter_p.c"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;_USRDLL;_ATL_ATTRIBUTES;_CRT_NONSTDC_NO_DEPRECATE;ZLIB_WINAPI;_CRT_SECURE_NO_DEPRECATE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1049"
|
||||
AdditionalIncludeDirectories="$(IntDir)"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="true"
|
||||
OutputFile="$(OutDir)/AVSEBOOKWriter.dll"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\AVSOfficeUtils\ZLIB\zlib123dll\static32;"
|
||||
IgnoreDefaultLibraryNames="LIBC.LIB"
|
||||
MergedIDLBaseFileName="_AVSEBOOKWriter.idl"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
ImportLibrary="$(OutDir)/AVSEBOOKWriter.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="Performing registration"
|
||||
CommandLine="regsvr32 /s /c "$(TargetPath)""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="2"
|
||||
UseOfATL="1"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
CommandLine="..\..\..\Redist\VersionControl.exe $(ProjectDir)version.h"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
MkTypLibCompatible="false"
|
||||
TargetEnvironment="1"
|
||||
GenerateStublessProxies="true"
|
||||
TypeLibraryName="$(IntDir)/AVSEBOOKWriter.tlb"
|
||||
HeaderFileName="AVSEBOOKWriter.h"
|
||||
DLLDataFileName=""
|
||||
InterfaceIdentifierFileName="AVSEBOOKWriter_i.c"
|
||||
ProxyFileName="AVSEBOOKWriter_p.c"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
InlineFunctionExpansion="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;_USRDLL;_ATL_ATTRIBUTES;_CRT_NONSTDC_NO_DEPRECATE;ZLIB_WINAPI;_CRT_SECURE_NO_DEPRECATE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1049"
|
||||
AdditionalIncludeDirectories="$(IntDir)"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="true"
|
||||
OutputFile="..\..\..\..\Redist\AVSOfficeStudio\$(ProjectName).dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\AVSOfficeUtils\ZLIB\zlib123dll\static32;"
|
||||
IgnoreDefaultLibraryNames="LIBC.LIB"
|
||||
MergedIDLBaseFileName="_AVSEBOOKWriter.idl"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
ImportLibrary="$(OutDir)/AVSEBOOKWriter.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="Performing registration"
|
||||
CommandLine="regsvr32 /s /c "$(TargetPath)"
copy "$(TargetPath)" "$(ProjectDir)..\..\..\Redist\AVSOfficeStudio"
"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\AVSEBOOKWriter.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\EBOOKWriter.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Objects.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\EBOOKWriter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Objects.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\version.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\AVSEBOOKWriter.rc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\AVSEBOOKWriter.rgs"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Logic"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Logic\EbookPage.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Logic\LogicItems.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Logic\LogicPage.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Logic\LogicPageDOCX.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Logic\LogicPagePDF.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Logic\Text.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Writers"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Writers\Format.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Writers\TempManager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Writers\Writer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Writers\Writer_Docx.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Writers\Writer_Epub.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Writers\Writer_Fb2.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Writers\Writer_Mobi.h"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="zip"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\adler32.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\compress.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\crc32.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\deflate.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\contrib\masmx86\gvmat32c.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\gzio.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\infback.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\contrib\masmx64\inffas8664.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\inffast.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\inflate.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\inftrees.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\contrib\minizip\ioapi.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\trees.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\uncompr.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\contrib\minizip\unzip.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\contrib\minizip\zip.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\AVSOfficeUtils\ZLIB\zlib-1.2.3\zutil.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Common"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Common\agg_trans_affine.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\agg_trans_affine.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\ap_AggPlusEnums.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\ap_AggPlusTypes.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\CalculatorCRC32.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\Common.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\File.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\FontManager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\fontmanagerbase.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\Matrix.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\StringWriter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\structures.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="MOBIFormat"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\MOBIFormat\MobiFile.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\MOBIFormat\MobiReader.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
87
AVSEBOOKWriter2/Common/CalculatorCRC32.h
Normal file
87
AVSEBOOKWriter2/Common/CalculatorCRC32.h
Normal file
@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
const long g_clFilePartSize = 20*1024;
|
||||
class CCalculatorCRC32
|
||||
{
|
||||
public:
|
||||
CCalculatorCRC32()
|
||||
{
|
||||
m_dwMagicWord = 0xEDB88320;
|
||||
m_dwInitCrc = 0xFFFFFFFF;
|
||||
m_bInitTable = FALSE;
|
||||
}
|
||||
public:
|
||||
DWORD Calc(BYTE const*pStream, int nSize)
|
||||
{
|
||||
InitCRCTable();
|
||||
DWORD dwRes = m_dwInitCrc;
|
||||
for (int i=0;i<nSize;i++)
|
||||
{
|
||||
dwRes = m_arCRCTable[(dwRes ^ pStream[i])& 0xFF] ^ (dwRes >> 8);
|
||||
}
|
||||
|
||||
dwRes = dwRes ^ 0xFFFFFFFF;
|
||||
return dwRes;
|
||||
}
|
||||
|
||||
DWORD Calc(const CString &sStream)
|
||||
{
|
||||
InitCRCTable();
|
||||
DWORD dwRes = m_dwInitCrc;
|
||||
int nSize = sStream.GetLength();
|
||||
for (int i=0;i<nSize;i++)
|
||||
{
|
||||
dwRes = m_arCRCTable[(dwRes ^ (BYTE)sStream[i]) & 0xFF] ^ (dwRes >> 8);
|
||||
}
|
||||
|
||||
dwRes = dwRes ^ 0xFFFFFFFF;
|
||||
return dwRes;
|
||||
}
|
||||
DWORD CalcPartFile(const CString &sFilepath)
|
||||
{
|
||||
DWORD dwRet = 0xFFFFFFFF;
|
||||
//LPBYTE pBuffer = new BYTE[g_clFilePartSize];
|
||||
//if (NULL==pBuffer)
|
||||
// return dwRet;
|
||||
//FILE *pFile = fopen(sFilepath, "rb");
|
||||
//if (NULL==pFile)
|
||||
//{
|
||||
// delete [] pBuffer;
|
||||
// return dwRet;
|
||||
//}
|
||||
|
||||
//size_t nReaded = fread(pBuffer, 1, 1024, pFile);
|
||||
//fclose(pFile);
|
||||
|
||||
//dwRet = CCalculatorCRC32::Calc(pBuffer, nReaded);
|
||||
//
|
||||
////ATLTRACE("CRC32: 0x%08X\n", dwRet);
|
||||
//delete [] pBuffer;
|
||||
return dwRet;
|
||||
}
|
||||
private:
|
||||
void InitCRCTable()
|
||||
{
|
||||
if (m_bInitTable)
|
||||
return;
|
||||
|
||||
DWORD dwTemp;
|
||||
for (int i=0;i<256;i++)
|
||||
{
|
||||
dwTemp = i;
|
||||
for (int j=0;j<8;j++)
|
||||
{
|
||||
if (0x1==(dwTemp & 0x1))
|
||||
dwTemp = (dwTemp >> 1) ^ m_dwMagicWord;
|
||||
else
|
||||
dwTemp = dwTemp >> 1;
|
||||
}
|
||||
m_arCRCTable[i] = dwTemp;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD m_dwMagicWord;
|
||||
DWORD m_dwInitCrc;
|
||||
DWORD m_arCRCTable[255];
|
||||
BOOL m_bInitTable;
|
||||
};
|
||||
610
AVSEBOOKWriter2/Common/Common.h
Normal file
610
AVSEBOOKWriter2/Common/Common.h
Normal file
@ -0,0 +1,610 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef AVSINLINE
|
||||
#if defined(_MSC_VER)
|
||||
#define AVSINLINE __forceinline
|
||||
#else
|
||||
#define AVSINLINE inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "TemporaryCS.h"
|
||||
#include "Matrix.h"
|
||||
#include "Structures.h"
|
||||
#include "StringWriter.h"
|
||||
#include "CalculatorCRC32.h"
|
||||
|
||||
const double c_dpiBook = 166;
|
||||
const long c_nMaxImageSize = 800;
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
AVSINLINE LONG ConvertColor(LONG lBGR)
|
||||
{
|
||||
return (0x00FFFFFF & (((lBGR & 0xFF) << 16) | (lBGR & 0x0000FF00) | ((lBGR >> 16) & 0xFF)));
|
||||
}
|
||||
|
||||
AVSINLINE void CorrectString(CString& strValue)
|
||||
{
|
||||
strValue.Replace(_T("&"), _T("&"));
|
||||
strValue.Replace(_T("'"), _T("'"));
|
||||
strValue.Replace(_T("<"), _T("<"));
|
||||
strValue.Replace(_T(">"), _T(">"));
|
||||
strValue.Replace(_T("\""), _T("""));
|
||||
}
|
||||
AVSINLINE CString CorrectString2(CString& str)
|
||||
{
|
||||
CString strValue = str;
|
||||
CorrectString(strValue);
|
||||
return strValue;
|
||||
}
|
||||
|
||||
class CDoubleRect
|
||||
{
|
||||
public:
|
||||
double left;
|
||||
double top;
|
||||
double right;
|
||||
double bottom;
|
||||
|
||||
public:
|
||||
CDoubleRect()
|
||||
{
|
||||
left = 0;
|
||||
top = 0;
|
||||
right = 0;
|
||||
bottom = 0;
|
||||
}
|
||||
CDoubleRect& operator=(const CDoubleRect& oSrc)
|
||||
{
|
||||
left = oSrc.left;
|
||||
top = oSrc.top;
|
||||
right = oSrc.right;
|
||||
bottom = oSrc.bottom;
|
||||
|
||||
return *this;
|
||||
}
|
||||
CDoubleRect(const CDoubleRect& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
inline bool IsEqual(const CDoubleRect& oSrc, double dEps = 0.01)
|
||||
{
|
||||
return ((fabs(left - oSrc.left) < dEps) && (fabs(top - oSrc.top) < dEps) &&
|
||||
(fabs(right - oSrc.right) < dEps) && (fabs(bottom - oSrc.bottom) < dEps));
|
||||
}
|
||||
|
||||
inline double GetWidth() const
|
||||
{
|
||||
return right - left;
|
||||
}
|
||||
inline double GetHeight() const
|
||||
{
|
||||
return bottom - top;
|
||||
}
|
||||
inline void Scale(const double& dKoef)
|
||||
{
|
||||
left *= dKoef;
|
||||
top *= dKoef;
|
||||
right *= dKoef;
|
||||
bottom *= dKoef;
|
||||
}
|
||||
|
||||
AVSINLINE void ClearBounds()
|
||||
{
|
||||
left = 1000000;
|
||||
top = 1000000;
|
||||
right = -1000000;
|
||||
bottom = -1000000;
|
||||
}
|
||||
|
||||
AVSINLINE void CheckBounds(const double& x, const double& y)
|
||||
{
|
||||
if (left > x)
|
||||
left = x;
|
||||
if (right < x)
|
||||
right = x;
|
||||
if (top > y)
|
||||
top = y;
|
||||
if (bottom < y)
|
||||
bottom = y;
|
||||
}
|
||||
};
|
||||
|
||||
class CImageManager
|
||||
{
|
||||
public:
|
||||
CAtlMap<CString, CImageInfo> m_mapImagesFile;
|
||||
CAtlMap<DWORD, CImageInfo> m_mapImageData;
|
||||
|
||||
CAtlList<CImageInfo> m_listImages;
|
||||
|
||||
CString m_strDstMedia;
|
||||
|
||||
LONG m_lMaxSizeImage;
|
||||
LONG m_lNextIDImage;
|
||||
|
||||
CCalculatorCRC32 m_oCRC;
|
||||
|
||||
LONG m_lDstFormat;
|
||||
|
||||
public:
|
||||
|
||||
CImageManager()
|
||||
{
|
||||
m_strDstMedia = _T("");
|
||||
m_lMaxSizeImage = c_nMaxImageSize;
|
||||
m_lNextIDImage = 0;
|
||||
m_lDstFormat = 0;
|
||||
}
|
||||
|
||||
AVSINLINE void NewDocument()
|
||||
{
|
||||
m_strDstMedia = _T("");
|
||||
m_lMaxSizeImage = 800;
|
||||
m_lNextIDImage = 0;
|
||||
|
||||
m_mapImageData.RemoveAll();
|
||||
m_mapImagesFile.RemoveAll();
|
||||
m_listImages.RemoveAll();
|
||||
}
|
||||
|
||||
public:
|
||||
CImageInfo WriteImage(IUnknown* punkImage, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
CImageInfo info;
|
||||
if (NULL == punkImage)
|
||||
return info;
|
||||
|
||||
if (height < 0)
|
||||
{
|
||||
FlipY(punkImage);
|
||||
height = -height;
|
||||
y -= height;
|
||||
}
|
||||
|
||||
return GenerateImageID(punkImage, max(1.0, width), max(1.0, height));
|
||||
}
|
||||
CImageInfo WriteImage(CString& strFile, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
CImageInfo info;
|
||||
CFile oFile;
|
||||
if (S_OK != oFile.OpenFile(strFile))
|
||||
return info;
|
||||
|
||||
oFile.CloseFile();
|
||||
return GenerateImageID(strFile, max(1.0, width), max(1.0, height));
|
||||
}
|
||||
|
||||
protected:
|
||||
inline void CopyFile(CString& strFileSrc, CString& strFileDst)
|
||||
{
|
||||
CDirectory::CopyFile(strFileSrc, strFileDst, NULL, NULL);
|
||||
}
|
||||
void SaveImage(CString& strFileSrc, CImageInfo& oInfo, LONG __width, LONG __height)
|
||||
{
|
||||
CString strLoadXml = _T("<transforms><ImageFile-LoadImage sourcepath=\"") + strFileSrc + _T("\"/></transforms>");
|
||||
|
||||
ImageStudio::IImageTransforms* pTransform = NULL;
|
||||
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("");
|
||||
|
||||
LONG lMaxSize = min(max(__width, __height), m_lMaxSizeImage);
|
||||
|
||||
if ((lWidth <= lMaxSize) && (lHeight <= lMaxSize))
|
||||
{
|
||||
strXml = _T("<transforms>") + strSaveItem + _T("</transforms>");
|
||||
}
|
||||
else
|
||||
{
|
||||
LONG lW = 0;
|
||||
LONG lH = 0;
|
||||
double dAspect = (double)lWidth / lHeight;
|
||||
|
||||
if (lWidth >= lHeight)
|
||||
{
|
||||
lW = lMaxSize;
|
||||
lH = (LONG)((double)lW / dAspect);
|
||||
}
|
||||
else
|
||||
{
|
||||
lH = lMaxSize;
|
||||
lW = (LONG)(dAspect * lH);
|
||||
}
|
||||
|
||||
CString strResize = _T("");
|
||||
strResize.Format(_T("<ImageTransform-TransformResize type=\"65536\" 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, LONG __width, LONG __height)
|
||||
{
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
if (NULL == pFrame)
|
||||
return;
|
||||
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
|
||||
oInfo.m_eType = GetImageType(pFrame);
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
|
||||
ImageStudio::IImageTransforms* pTransform = NULL;
|
||||
CoCreateInstance(ImageStudio::CLSID_ImageTransforms, NULL ,CLSCTX_INPROC_SERVER, ImageStudio::IID_IImageTransforms, (void**)&pTransform);
|
||||
|
||||
VARIANT var;
|
||||
var.vt = VT_UNKNOWN;
|
||||
var.punkVal = punkImage;
|
||||
pTransform->SetSource(0, var);
|
||||
|
||||
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\"/>");
|
||||
}
|
||||
|
||||
LONG lMaxSize = min(max(__width, __height), m_lMaxSizeImage);
|
||||
|
||||
CString strXml = _T("");
|
||||
if ((lWidth <= lMaxSize) && (lHeight <= lMaxSize))
|
||||
{
|
||||
strXml = _T("<transforms>") + strSaveItem + _T("</transforms>");
|
||||
}
|
||||
else
|
||||
{
|
||||
LONG lW = 0;
|
||||
LONG lH = 0;
|
||||
double dAspect = (double)lWidth / lHeight;
|
||||
|
||||
if (lWidth >= lHeight)
|
||||
{
|
||||
lW = lMaxSize;
|
||||
lH = (LONG)((double)lW / dAspect);
|
||||
}
|
||||
else
|
||||
{
|
||||
lH = lMaxSize;
|
||||
lW = (LONG)(dAspect * lH);
|
||||
}
|
||||
|
||||
CString strResize = _T("");
|
||||
strResize.Format(_T("<ImageTransform-TransformResize type=\"65536\" 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, double dWidth, double dHeight)
|
||||
{
|
||||
CImageInfo oInfo;
|
||||
|
||||
if (NULL == punkData)
|
||||
return oInfo;
|
||||
|
||||
LONG lWidth = (LONG)(dWidth * 96 / 25.4);
|
||||
LONG lHeight = (LONG)(dHeight * 96 / 25.4);
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkData->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
LONG lLen = 0;
|
||||
|
||||
pFrame->get_Buffer(&pBuffer);
|
||||
pFrame->get_BufferSize(&lLen);
|
||||
|
||||
DWORD dwSum = m_oCRC.Calc(pBuffer, lLen);
|
||||
|
||||
CAtlMap<DWORD, CImageInfo>::CPair* pPair = m_mapImageData.Lookup(dwSum);
|
||||
if (NULL == pPair)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
++m_lNextIDImage;
|
||||
|
||||
oInfo.m_lID = m_lNextIDImage;
|
||||
SaveImage(punkData, oInfo, lWidth, lHeight);
|
||||
m_mapImageData.SetAt(dwSum, oInfo);
|
||||
m_listImages.AddTail(oInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
oInfo = pPair->m_value;
|
||||
}
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
|
||||
return oInfo;
|
||||
}
|
||||
|
||||
CImageInfo GenerateImageID(CString& strFileName, double dWidth, double dHeight)
|
||||
{
|
||||
CImageInfo oInfo;
|
||||
CAtlMap<CString, CImageInfo>::CPair* pPair = m_mapImagesFile.Lookup(strFileName);
|
||||
|
||||
LONG lWidth = (LONG)(dWidth * 96 / 25.4);
|
||||
LONG lHeight = (LONG)(dHeight * 96 / 25.4);
|
||||
|
||||
if (NULL == pPair)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
++m_lNextIDImage;
|
||||
|
||||
oInfo.m_lID = m_lNextIDImage;
|
||||
SaveImage(strFileName, oInfo, lWidth, lHeight);
|
||||
m_mapImagesFile.SetAt(strFileName, oInfo);
|
||||
m_listImages.AddTail(oInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
oInfo = pPair->m_value;
|
||||
}
|
||||
|
||||
return oInfo;
|
||||
}
|
||||
|
||||
ImageType GetImageType(MediaCore::IAVSUncompressedVideoFrame* pFrame)
|
||||
{
|
||||
if (2 == m_lDstFormat)
|
||||
return itJPG;
|
||||
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
BYTE* pBuffer = NULL;
|
||||
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
pFrame->get_Buffer(&pBuffer);
|
||||
|
||||
BYTE* pBufferMem = pBuffer + 3;
|
||||
LONG lCountPix = lWidth * lHeight;
|
||||
|
||||
for (LONG i = 0; i < lCountPix; ++i, pBufferMem += 4)
|
||||
{
|
||||
if (255 != *pBufferMem)
|
||||
return itPNG;
|
||||
}
|
||||
return itJPG;
|
||||
}
|
||||
|
||||
void FlipY(IUnknown* punkImage)
|
||||
{
|
||||
if (NULL == punkImage)
|
||||
return;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
if (NULL == pFrame)
|
||||
return;
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
LONG lWidth = 0;
|
||||
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)
|
||||
{
|
||||
RELEASEINTERFACE(pFrame);
|
||||
return;
|
||||
}
|
||||
|
||||
BYTE* pBufferMem = new BYTE[lStride];
|
||||
|
||||
BYTE* pBufferEnd = pBuffer + lStride * (lHeight - 1);
|
||||
|
||||
LONG lCountV = lHeight / 2;
|
||||
|
||||
for (LONG lIndexV = 0; lIndexV < lCountV; ++lIndexV)
|
||||
{
|
||||
memcpy(pBufferMem, pBuffer, lStride);
|
||||
memcpy(pBuffer, pBufferEnd, lStride);
|
||||
memcpy(pBufferEnd, pBufferMem, lStride);
|
||||
|
||||
pBuffer += lStride;
|
||||
pBufferEnd -= lStride;
|
||||
}
|
||||
|
||||
RELEASEARRAYOBJECTS(pBufferMem);
|
||||
RELEASEINTERFACE(pFrame);
|
||||
}
|
||||
|
||||
void FlipX(IUnknown* punkImage)
|
||||
{
|
||||
if (NULL == punkImage)
|
||||
return;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
if (NULL == pFrame)
|
||||
return;
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
LONG lWidth = 0;
|
||||
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)
|
||||
{
|
||||
RELEASEINTERFACE(pFrame);
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD* pBufferDWORD = (DWORD*)pBuffer;
|
||||
|
||||
LONG lW2 = lWidth / 2;
|
||||
for (LONG lIndexV = 0; lIndexV < lHeight; ++lIndexV)
|
||||
{
|
||||
DWORD* pMem1 = pBufferDWORD;
|
||||
DWORD* pMem2 = pBufferDWORD + lWidth - 1;
|
||||
|
||||
LONG lI = 0;
|
||||
while (lI < lW2)
|
||||
{
|
||||
DWORD dwMem = *pMem1;
|
||||
*pMem1++ = *pMem2;
|
||||
*pMem2-- = dwMem;
|
||||
}
|
||||
}
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
// 2-byte number
|
||||
AVSINLINE short little_endian_2_big_endian( short s )
|
||||
{
|
||||
return ( ( s >> 8) & 0xff ) + ( ( s << 8 ) & 0xff00 );
|
||||
}
|
||||
|
||||
/*========================================================================================================*/
|
||||
|
||||
// 4-byte number
|
||||
AVSINLINE int little_endian_2_big_endian( int i )
|
||||
{
|
||||
return ( ( i & 0xff ) << 24 ) + ( ( i & 0xff00 ) << 8 ) + ( ( i & 0xff0000 ) >> 8 ) + ( ( i >> 24 ) & 0xff );
|
||||
}
|
||||
|
||||
AVSINLINE CString ToHexString( unsigned int ui )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/*========================================================================================================*/
|
||||
}
|
||||
460
AVSEBOOKWriter2/Common/File.h
Normal file
460
AVSEBOOKWriter2/Common/File.h
Normal file
@ -0,0 +1,460 @@
|
||||
#pragma once
|
||||
#include "windows.h"
|
||||
|
||||
class CFile
|
||||
{
|
||||
public:
|
||||
CFile()
|
||||
{
|
||||
m_hFileHandle = NULL;
|
||||
m_lFileSize = 0;
|
||||
m_lFilePosition = 0;
|
||||
}
|
||||
|
||||
virtual ~CFile()
|
||||
{
|
||||
CloseFile();
|
||||
}
|
||||
|
||||
virtual HRESULT OpenFile(CString FileName)
|
||||
{
|
||||
CloseFile();
|
||||
|
||||
HRESULT hRes = S_OK;
|
||||
DWORD AccessMode = GENERIC_READ;
|
||||
DWORD ShareMode = FILE_SHARE_READ;
|
||||
DWORD Disposition = OPEN_EXISTING;
|
||||
m_hFileHandle = ::CreateFile(FileName, AccessMode, ShareMode, NULL, Disposition, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
if (NULL == m_hFileHandle || INVALID_HANDLE_VALUE == m_hFileHandle)
|
||||
hRes = S_FALSE;
|
||||
else
|
||||
{
|
||||
ULARGE_INTEGER nTempSize;
|
||||
nTempSize.LowPart = ::GetFileSize(m_hFileHandle, &nTempSize.HighPart);
|
||||
m_lFileSize = nTempSize.QuadPart;
|
||||
|
||||
SetPosition(0);
|
||||
}
|
||||
|
||||
return hRes;
|
||||
}
|
||||
|
||||
virtual HRESULT OpenFileRW(CString FileName)
|
||||
{
|
||||
CloseFile();
|
||||
|
||||
HRESULT hRes = S_OK;
|
||||
DWORD AccessMode = GENERIC_READ | GENERIC_WRITE;
|
||||
DWORD ShareMode = FILE_SHARE_READ;
|
||||
DWORD Disposition = OPEN_EXISTING;
|
||||
m_hFileHandle = ::CreateFile(FileName, AccessMode, ShareMode, NULL, Disposition, 0, 0);
|
||||
|
||||
if (NULL == m_hFileHandle || INVALID_HANDLE_VALUE == m_hFileHandle)
|
||||
{
|
||||
hRes = S_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ULARGE_INTEGER nTempSize;
|
||||
nTempSize.LowPart = ::GetFileSize(m_hFileHandle, &nTempSize.HighPart);
|
||||
m_lFileSize = nTempSize.QuadPart;
|
||||
|
||||
SetPosition(0);
|
||||
}
|
||||
|
||||
return hRes;
|
||||
}
|
||||
|
||||
HRESULT ReadFile(BYTE* pData, DWORD nBytesToRead)
|
||||
{
|
||||
DWORD nBytesRead = 0;
|
||||
if(NULL == pData)
|
||||
return S_FALSE;
|
||||
|
||||
if(m_hFileHandle && (pData))
|
||||
{
|
||||
SetPosition(m_lFilePosition);
|
||||
::ReadFile(m_hFileHandle, pData, nBytesToRead, &nBytesRead, NULL);
|
||||
m_lFilePosition += nBytesRead;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT ReadFile2(BYTE* pData, DWORD nBytesToRead)
|
||||
{
|
||||
DWORD nBytesRead = 0;
|
||||
if(NULL == pData)
|
||||
return S_FALSE;
|
||||
|
||||
if(m_hFileHandle && (pData))
|
||||
{
|
||||
SetPosition(m_lFilePosition);
|
||||
::ReadFile(m_hFileHandle, pData, nBytesToRead, &nBytesRead, NULL);
|
||||
m_lFilePosition += nBytesRead;
|
||||
|
||||
for (size_t index = 0; index < nBytesToRead / 2; ++index)
|
||||
{
|
||||
BYTE temp = pData[index];
|
||||
pData[index] = pData[nBytesToRead - index - 1];
|
||||
pData[nBytesToRead - index - 1] = temp;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT ReadFile3(void* pData, DWORD nBytesToRead)
|
||||
{
|
||||
DWORD nBytesRead = 0;
|
||||
if(NULL == pData)
|
||||
return S_FALSE;
|
||||
|
||||
if(m_hFileHandle && (pData))
|
||||
{
|
||||
SetPosition(m_lFilePosition);
|
||||
::ReadFile(m_hFileHandle, pData, nBytesToRead, &nBytesRead, NULL);
|
||||
m_lFilePosition += nBytesRead;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
CString ReadStringFromUTF8(DWORD nLength)
|
||||
{
|
||||
BYTE* pData = new BYTE[nLength];
|
||||
this->ReadFile(pData, nLength);
|
||||
CString strRes = GetCStringFromUTF8(pData, nLength);
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
return strRes;
|
||||
}
|
||||
DWORD ReadDWORD()
|
||||
{
|
||||
DWORD dwVal = 0;
|
||||
this->ReadFile2((BYTE*)&dwVal, 4);
|
||||
return dwVal;
|
||||
}
|
||||
BYTE ReadBYTE()
|
||||
{
|
||||
BYTE dwVal = 0;
|
||||
this->ReadFile2(&dwVal, 1);
|
||||
return dwVal;
|
||||
}
|
||||
|
||||
static CString GetCStringFromUTF8( BYTE* pBuffer, LONG lCount, BOOL bIsRemoveCode = FALSE )
|
||||
{
|
||||
if (bIsRemoveCode)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>...
|
||||
while (('>' != *pBuffer) && (lCount > 0))
|
||||
{
|
||||
++pBuffer;
|
||||
--lCount;
|
||||
}
|
||||
++pBuffer;
|
||||
--lCount;
|
||||
}
|
||||
|
||||
LONG lLenght = 0;
|
||||
|
||||
TCHAR* pUnicodeString = new TCHAR[lCount + 1];
|
||||
LONG lIndexUnicode = 0;
|
||||
|
||||
for (LONG lIndex = 0; lIndex < lCount; ++lIndex)
|
||||
{
|
||||
if (0x00 == (0x80 & pBuffer[lIndex]))
|
||||
{
|
||||
//strRes += (TCHAR)pBuffer[lIndex];
|
||||
pUnicodeString[lIndexUnicode++] = (WCHAR)pBuffer[lIndex];
|
||||
continue;
|
||||
}
|
||||
else if (0x00 == (0x20 & pBuffer[lIndex]))
|
||||
{
|
||||
TCHAR mem = (TCHAR)(((pBuffer[lIndex] & 0x1F) << 6) + (pBuffer[lIndex + 1] & 0x3F));
|
||||
|
||||
//strRes += mem;
|
||||
pUnicodeString[lIndexUnicode++] = mem;
|
||||
|
||||
lIndex += 1;
|
||||
}
|
||||
else if (0x00 == (0x10 & pBuffer[lIndex]))
|
||||
{
|
||||
TCHAR mem = (TCHAR)(((pBuffer[lIndex] & 0x0F) << 12) + ((pBuffer[lIndex + 1] & 0x3F) << 6) + (pBuffer[lIndex + 2] & 0x3F));
|
||||
|
||||
//strRes += mem;
|
||||
pUnicodeString[lIndexUnicode++] = mem;
|
||||
|
||||
lIndex += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
BYTE mem = pBuffer[lIndex];
|
||||
//pUnicodeString[lIndexUnicode++] = mem;
|
||||
}
|
||||
}
|
||||
|
||||
pUnicodeString[lIndexUnicode] = 0;
|
||||
|
||||
CString strRes = (CString)pUnicodeString;
|
||||
RELEASEARRAYOBJECTS(pUnicodeString);
|
||||
|
||||
return strRes;
|
||||
}
|
||||
|
||||
HRESULT WriteFile(void* pData, DWORD nBytesToWrite)
|
||||
{
|
||||
if(m_hFileHandle)
|
||||
{
|
||||
DWORD dwWritten = 0;
|
||||
::WriteFile(m_hFileHandle, pData, nBytesToWrite, &dwWritten, NULL);
|
||||
m_lFilePosition += nBytesToWrite;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT WriteFile2(void* pData, DWORD nBytesToWrite)
|
||||
{
|
||||
if(m_hFileHandle)
|
||||
{
|
||||
BYTE* mem = new BYTE[nBytesToWrite];
|
||||
memcpy(mem, pData, nBytesToWrite);
|
||||
|
||||
for (size_t index = 0; index < nBytesToWrite / 2; ++index)
|
||||
{
|
||||
BYTE temp = mem[index];
|
||||
mem[index] = mem[nBytesToWrite - index - 1];
|
||||
mem[nBytesToWrite - index - 1] = temp;
|
||||
}
|
||||
|
||||
DWORD dwWritten = 0;
|
||||
::WriteFile(m_hFileHandle, (void*)mem, nBytesToWrite, &dwWritten, NULL);
|
||||
m_lFilePosition += nBytesToWrite;
|
||||
RELEASEARRAYOBJECTS(mem);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CreateFile(CString strFileName)
|
||||
{
|
||||
CloseFile();
|
||||
DWORD AccessMode = GENERIC_WRITE;
|
||||
DWORD ShareMode = FILE_SHARE_WRITE;
|
||||
DWORD Disposition = CREATE_ALWAYS;
|
||||
m_hFileHandle = ::CreateFile(strFileName, AccessMode, ShareMode, NULL, Disposition, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
return SetPosition(0);
|
||||
}
|
||||
HRESULT SetPosition( ULONG64 nPos )
|
||||
{
|
||||
if (m_hFileHandle && nPos < (ULONG)m_lFileSize)
|
||||
{
|
||||
LARGE_INTEGER nTempPos;
|
||||
nTempPos.QuadPart = nPos;
|
||||
::SetFilePointer(m_hFileHandle, nTempPos.LowPart, &nTempPos.HighPart, FILE_BEGIN);
|
||||
m_lFilePosition = nPos;
|
||||
return S_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (INVALID_HANDLE_VALUE == m_hFileHandle) ? S_FALSE : S_OK;
|
||||
}
|
||||
}
|
||||
LONG64 GetPosition()
|
||||
{
|
||||
return m_lFilePosition;
|
||||
}
|
||||
HRESULT SkipBytes(ULONG64 nCount)
|
||||
{
|
||||
return SetPosition(m_lFilePosition + nCount);
|
||||
}
|
||||
|
||||
HRESULT CloseFile()
|
||||
{
|
||||
m_lFileSize = 0;
|
||||
m_lFilePosition = 0;
|
||||
RELEASEHANDLE(m_hFileHandle);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
ULONG64 GetFileSize()
|
||||
{
|
||||
return m_lFileSize;
|
||||
}
|
||||
|
||||
HRESULT WriteReserved(DWORD dwCount)
|
||||
{
|
||||
BYTE* buf = new BYTE[dwCount];
|
||||
memset(buf, 0, (size_t)dwCount);
|
||||
HRESULT hr = WriteFile(buf, dwCount);
|
||||
RELEASEARRAYOBJECTS(buf);
|
||||
return hr;
|
||||
}
|
||||
HRESULT WriteReserved2(DWORD dwCount)
|
||||
{
|
||||
BYTE* buf = new BYTE[dwCount];
|
||||
memset(buf, 0xFF, (size_t)dwCount);
|
||||
HRESULT hr = WriteFile(buf, dwCount);
|
||||
RELEASEARRAYOBJECTS(buf);
|
||||
return hr;
|
||||
}
|
||||
HRESULT WriteReservedTo(DWORD dwPoint)
|
||||
{
|
||||
if (m_lFilePosition >= dwPoint)
|
||||
return S_OK;
|
||||
|
||||
DWORD dwCount = dwPoint - (DWORD)m_lFilePosition;
|
||||
BYTE* buf = new BYTE[dwCount];
|
||||
memset(buf, 0, (size_t)dwCount);
|
||||
HRESULT hr = WriteFile(buf, dwCount);
|
||||
RELEASEARRAYOBJECTS(buf);
|
||||
return hr;
|
||||
}
|
||||
HRESULT SkipReservedTo(DWORD dwPoint)
|
||||
{
|
||||
if (m_lFilePosition >= dwPoint)
|
||||
return S_OK;
|
||||
|
||||
DWORD dwCount = dwPoint - (DWORD)m_lFilePosition;
|
||||
return SkipBytes(dwCount);
|
||||
}
|
||||
|
||||
LONG GetProgress()
|
||||
{
|
||||
if (0 >= m_lFileSize)
|
||||
return -1;
|
||||
|
||||
double dVal = (double)(100 * m_lFilePosition);
|
||||
LONG lProgress = (LONG)(dVal / m_lFileSize);
|
||||
return lProgress;
|
||||
}
|
||||
|
||||
void WriteStringUTF8(CString& strXml)
|
||||
{
|
||||
int nLength = strXml.GetLength();
|
||||
|
||||
CStringA saStr;
|
||||
|
||||
#ifdef UNICODE
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, strXml.GetBuffer(), nLength + 1, saStr.GetBuffer(nLength*3 + 1), nLength*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
#else
|
||||
wchar_t* pWStr = new wchar_t[nLength + 1];
|
||||
if (!pWStr)
|
||||
return;
|
||||
|
||||
// set end string
|
||||
pWStr[nLength] = 0;
|
||||
|
||||
// Encoding ASCII to Unicode
|
||||
MultiByteToWideChar(CP_ACP, 0, strXml, nLength, pWStr, nLength);
|
||||
|
||||
int nLengthW = (int)wcslen(pWStr);
|
||||
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, pWStr, nLengthW + 1, saStr.GetBuffer(nLengthW*3 + 1), nLengthW*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
|
||||
delete[] pWStr;
|
||||
#endif
|
||||
|
||||
WriteFile((void*)saStr.GetBuffer(), saStr.GetLength());
|
||||
}
|
||||
|
||||
protected:
|
||||
HANDLE m_hFileHandle;
|
||||
LONG64 m_lFileSize;
|
||||
LONG64 m_lFilePosition;
|
||||
};
|
||||
|
||||
namespace CDirectory
|
||||
{
|
||||
static CString GetFolderName(CString strFolderPath)
|
||||
{
|
||||
int n1 = strFolderPath.ReverseFind('\\');
|
||||
if (-1 == n1)
|
||||
return _T("");
|
||||
|
||||
return strFolderPath.Mid(n1 + 1);
|
||||
}
|
||||
static BOOL OpenFile(CString strFolderPath, CString strFileName, CFile* pFile)
|
||||
{
|
||||
CString strFile = strFolderPath + '\\' + strFileName;
|
||||
return (S_OK == pFile->OpenFile(strFile));
|
||||
}
|
||||
static BOOL CreateFile(CString strFolderPath, CString strFileName, CFile* pFile)
|
||||
{
|
||||
CString strFile = strFolderPath + '\\' + strFileName;
|
||||
return (S_OK == pFile->CreateFile(strFile));
|
||||
}
|
||||
static BOOL CreateDirectory(CString strFolderPathRoot, CString strFolderName)
|
||||
{
|
||||
CString strFolder = strFolderPathRoot + '\\' + strFolderName;
|
||||
return ::CreateDirectory(strFolder, NULL);
|
||||
}
|
||||
static BOOL CreateDirectory(CString strFolderPath)
|
||||
{
|
||||
return ::CreateDirectory(strFolderPath, NULL);
|
||||
}
|
||||
|
||||
static BOOL MoveFile(CString strExists, CString strNew, LPPROGRESS_ROUTINE lpFunc, LPVOID lpData)
|
||||
{
|
||||
#if (_WIN32_WINNT >= 0x0500)
|
||||
return ::MoveFileWithProgress(strExists, strNew, lpFunc, lpData, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
|
||||
#else
|
||||
return ::MoveFileEx(strExists, strNew, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
|
||||
#endif
|
||||
}
|
||||
|
||||
static BOOL CopyFile(CString strExists, CString strNew, LPPROGRESS_ROUTINE lpFunc, LPVOID lpData)
|
||||
{
|
||||
DeleteFile(strNew);
|
||||
return ::CopyFileEx(strExists, strNew, lpFunc, lpData, FALSE, 0);
|
||||
}
|
||||
|
||||
static CString GetUnder(CString strFolderPathRoot, CString strFolderName)
|
||||
{
|
||||
CString strFolder = strFolderPathRoot + '\\' + strFolderName;
|
||||
return strFolder;
|
||||
}
|
||||
|
||||
static CString GetFileName(CString strFullName)
|
||||
{
|
||||
int nStart = strFullName.ReverseFind('\\');
|
||||
CString strName = strFullName.Mid(nStart + 1);
|
||||
return strName;
|
||||
}
|
||||
|
||||
static void SaveToFile(CString strFileName, CString strXml)
|
||||
{
|
||||
int nLength = strXml.GetLength();
|
||||
|
||||
CStringA saStr;
|
||||
|
||||
#ifdef UNICODE
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, strXml.GetBuffer(), nLength + 1, saStr.GetBuffer(nLength*3 + 1), nLength*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
#else
|
||||
wchar_t* pWStr = new wchar_t[nLength + 1];
|
||||
if (!pWStr)
|
||||
return;
|
||||
|
||||
// set end string
|
||||
pWStr[nLength] = 0;
|
||||
|
||||
// Encoding ASCII to Unicode
|
||||
MultiByteToWideChar(CP_ACP, 0, strXml, nLength, pWStr, nLength);
|
||||
|
||||
int nLengthW = (int)wcslen(pWStr);
|
||||
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, pWStr, nLengthW + 1, saStr.GetBuffer(nLengthW*3 + 1), nLengthW*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
|
||||
delete[] pWStr;
|
||||
#endif
|
||||
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strFileName);
|
||||
oFile.WriteFile((void*)saStr.GetBuffer(), saStr.GetLength());
|
||||
oFile.CloseFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
267
AVSEBOOKWriter2/Common/FontManager.h
Normal file
267
AVSEBOOKWriter2/Common/FontManager.h
Normal file
@ -0,0 +1,267 @@
|
||||
#pragma once
|
||||
#include "Common.h"
|
||||
#include "FontManagerBase.h"
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
using namespace NSFontManager;
|
||||
|
||||
const double c_dDpiX = 72.0;
|
||||
const double c_dDpiY = 72.0;
|
||||
|
||||
class CFontManager : public CFontManagerBase
|
||||
{
|
||||
public:
|
||||
NSStructures::CFont* m_pFont;
|
||||
NSCommon::CMatrix* m_pTransform;
|
||||
|
||||
double m_dSpaceWidthMM;
|
||||
|
||||
public:
|
||||
CFontManager() : m_pFont(NULL), CFontManagerBase()
|
||||
{
|
||||
m_pTransform = NULL;
|
||||
m_dSpaceWidthMM = 0;
|
||||
}
|
||||
virtual ~CFontManager()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void LoadFont(long lFaceIndex = 0, bool bIsNeedAddToMap = true)
|
||||
{
|
||||
if (NULL == m_pManager)
|
||||
return;
|
||||
|
||||
double dSize = m_pFont->Size;
|
||||
double dSizeFont = dSize * ((m_pTransform->m_agg_mtx.sx + m_pTransform->m_agg_mtx.sy) / 2);
|
||||
|
||||
m_pFont->Size = dSizeFont;
|
||||
|
||||
if (m_pFont->IsEqual2(&m_oFont.m_oFont))
|
||||
{
|
||||
m_pFont->Size = dSize;
|
||||
return;
|
||||
}
|
||||
|
||||
m_oFont.m_oFont = *m_pFont;
|
||||
m_pFont->Size = dSize;
|
||||
|
||||
bool bIsPath = false;
|
||||
|
||||
if (_T("") == m_pFont->Path)
|
||||
{
|
||||
CFontManagerBase::LoadFontByName(m_oFont.m_oFont.Name, m_oFont.m_oFont.Size, m_oFont.m_oFont.GetStyle());
|
||||
}
|
||||
else
|
||||
{
|
||||
CFontManagerBase::LoadFontByFile(m_oFont.m_oFont.Path, m_oFont.m_oFont.Size, lFaceIndex);
|
||||
|
||||
m_pFont->SetStyle(m_oFont.m_oProperties.m_lStyle);
|
||||
m_oFont.m_oFont.SetStyle(m_oFont.m_oProperties.m_lStyle);
|
||||
|
||||
bIsPath = true;
|
||||
}
|
||||
|
||||
CalculateSpace();
|
||||
}
|
||||
|
||||
AVSINLINE void CalculateSpace()
|
||||
{
|
||||
LONG lGid = 0;
|
||||
m_pManager->GetStringGID(&lGid);
|
||||
m_pManager->SetStringGID(FALSE);
|
||||
|
||||
m_pManager->LoadString(L" ", 0, 0);
|
||||
float _x = 0;
|
||||
float _y = 0;
|
||||
float _w = 0;
|
||||
float _h = 0;
|
||||
|
||||
m_pManager->MeasureString2(&_x, &_y, &_w, &_h);
|
||||
|
||||
m_dSpaceWidthMM = (double)_w * c_dPixToMM;
|
||||
if (0 >= m_dSpaceWidthMM)
|
||||
{
|
||||
m_dSpaceWidthMM = 1.0;
|
||||
}
|
||||
|
||||
m_pManager->SetStringGID(lGid);
|
||||
}
|
||||
};
|
||||
|
||||
class CFontDstGenerator
|
||||
{
|
||||
public:
|
||||
NSStructures::CFont* m_pFonts;
|
||||
LONG m_lCurrentIndex;
|
||||
LONG m_lCountFonts;
|
||||
LONG m_lSize;
|
||||
|
||||
public:
|
||||
CFontDstGenerator()
|
||||
{
|
||||
m_lSize = 50;
|
||||
m_pFonts = NULL;
|
||||
m_lCurrentIndex = -1;
|
||||
m_lCountFonts = 0;
|
||||
|
||||
Grow();
|
||||
}
|
||||
~CFontDstGenerator()
|
||||
{
|
||||
RELEASEARRAYOBJECTS(m_pFonts);
|
||||
}
|
||||
public:
|
||||
LONG AddFont(NSStructures::CFont* pFont, BOOL bIsFontChanged, CFontManagerBase* pBase)
|
||||
{
|
||||
if (-1 != m_lCurrentIndex && !bIsFontChanged)
|
||||
return m_lCurrentIndex;
|
||||
|
||||
LONG lIndex = m_lCountFonts - 1;
|
||||
while (lIndex >= 0)
|
||||
{
|
||||
if (m_pFonts[lIndex].IsEqual4(pFont))
|
||||
break;
|
||||
--lIndex;
|
||||
}
|
||||
if (lIndex >= 0)
|
||||
{
|
||||
m_lCurrentIndex = lIndex;
|
||||
return m_lCurrentIndex;
|
||||
}
|
||||
|
||||
if (m_lCountFonts == m_lSize)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Grow();
|
||||
}
|
||||
|
||||
m_lCurrentIndex = m_lCountFonts;
|
||||
++m_lCountFonts;
|
||||
m_pFonts[m_lCurrentIndex] = *pFont;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>...
|
||||
m_pFonts[m_lCurrentIndex].Path = pBase->GetFontPath(&m_pFonts[m_lCurrentIndex]);
|
||||
return m_lCurrentIndex;
|
||||
}
|
||||
|
||||
LONG AddFont2(NSStructures::CFont* pFont, BOOL bIsFontChanged, CFontManagerBase* pBase)
|
||||
{
|
||||
if (-1 != m_lCurrentIndex && !bIsFontChanged)
|
||||
return m_lCurrentIndex;
|
||||
|
||||
CString strName = pFont->Name;
|
||||
LONG lStyle = pFont->GetStyle();
|
||||
|
||||
pFont->Name = pBase->m_strCurrentPickFont;
|
||||
pFont->SetStyle(pBase->m_lCurrentPictFontStyle);
|
||||
|
||||
LONG lIndex = m_lCountFonts - 1;
|
||||
while (lIndex >= 0)
|
||||
{
|
||||
if (m_pFonts[lIndex].IsEqual4(pFont))
|
||||
break;
|
||||
--lIndex;
|
||||
}
|
||||
if (lIndex >= 0)
|
||||
{
|
||||
m_lCurrentIndex = lIndex;
|
||||
|
||||
pFont->Name = strName;
|
||||
pFont->SetStyle(lStyle);
|
||||
|
||||
return m_lCurrentIndex;
|
||||
}
|
||||
|
||||
if (m_lCountFonts == m_lSize)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Grow();
|
||||
}
|
||||
|
||||
m_lCurrentIndex = m_lCountFonts;
|
||||
++m_lCountFonts;
|
||||
m_pFonts[m_lCurrentIndex] = *pFont;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>...
|
||||
m_pFonts[m_lCurrentIndex].Path = pBase->GetFontPath(&m_pFonts[m_lCurrentIndex]);
|
||||
|
||||
pFont->Name = strName;
|
||||
pFont->SetStyle(lStyle);
|
||||
|
||||
return m_lCurrentIndex;
|
||||
}
|
||||
|
||||
public:
|
||||
void WriteFonts(CString strFolderDst, CString& strCSS, CString& strItems)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> css
|
||||
strCSS = _T("");
|
||||
strItems = _T("");
|
||||
for (LONG nFont = 0; nFont < m_lCountFonts; ++nFont)
|
||||
{
|
||||
CString strName = m_pFonts[nFont].Name;
|
||||
strName.Replace(_T(" "), _T("_avs_space_"));
|
||||
|
||||
CString strCssMem = _T("@font-face {font-family:") + strName + _T(";font-weight:");
|
||||
if (m_pFonts[nFont].Bold)
|
||||
strCssMem += _T("bold;font-style:");
|
||||
else
|
||||
strCssMem += _T("normal;font-style:");
|
||||
|
||||
if (m_pFonts[nFont].Italic)
|
||||
strCssMem += _T("italic;src:url(fonts/");
|
||||
else
|
||||
strCssMem += _T("normal;src:url(fonts/");
|
||||
|
||||
int nStart1 = m_pFonts[nFont].Path.ReverseFind((TCHAR)'\\');
|
||||
int nStart2 = m_pFonts[nFont].Path.ReverseFind((TCHAR)'/');
|
||||
|
||||
int nStart = max(nStart1, nStart2);
|
||||
int nEnd = m_pFonts[nFont].Path.GetLength();
|
||||
|
||||
CString strDstName = m_pFonts[nFont].Path.Mid(nStart + 1, nEnd - nStart - 1);
|
||||
strDstName.Replace(_T(" "), _T("_avs_space_"));
|
||||
CString strFile = strFolderDst + _T("\\fonts\\") + strDstName;
|
||||
|
||||
DWORD dwFileAttrib = ::GetFileAttributes(strFile);
|
||||
if (dwFileAttrib == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
|
||||
::CopyFile(m_pFonts[nFont].Path, strFile, TRUE);
|
||||
}
|
||||
|
||||
nEnd = strDstName.Find(TCHAR('.'));
|
||||
CString strId = strDstName;
|
||||
if (-1 != nEnd)
|
||||
strId = strId.Mid(0, nEnd);
|
||||
|
||||
strItems += (_T("<item id=\"") + strId + _T("\" href=\"fonts/") + strDstName + _T("\" media-type=\"application/x-font-ttf\"/>"));
|
||||
|
||||
strCssMem += strDstName;
|
||||
strCssMem += _T(");}\n");
|
||||
|
||||
strCSS += strCssMem;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
void Grow()
|
||||
{
|
||||
if (NULL == m_pFonts)
|
||||
{
|
||||
m_pFonts = new NSStructures::CFont[m_lSize];
|
||||
return;
|
||||
}
|
||||
|
||||
NSStructures::CFont* pNewBuffer = new NSStructures::CFont[m_lSize * 2];
|
||||
for (LONG i = 0; i < m_lSize; ++i)
|
||||
{
|
||||
pNewBuffer[i] = m_pFonts[i];
|
||||
}
|
||||
RELEASEARRAYOBJECTS(m_pFonts);
|
||||
m_pFonts = pNewBuffer;
|
||||
}
|
||||
};
|
||||
}
|
||||
173
AVSEBOOKWriter2/Common/Matrix.h
Normal file
173
AVSEBOOKWriter2/Common/Matrix.h
Normal file
@ -0,0 +1,173 @@
|
||||
#pragma once
|
||||
|
||||
#include "ap_AggPlusEnums.h"
|
||||
#include "ap_AggPlusTypes.h"
|
||||
#include "agg_trans_affine.h"
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
class CMatrix
|
||||
{
|
||||
public:
|
||||
CMatrix(double m11, double m12, double m21, double m22, double dx, double dy) : m_agg_mtx(m11, m12, m21, m22, dx, dy)
|
||||
{
|
||||
}
|
||||
|
||||
CMatrix() : m_agg_mtx()
|
||||
{
|
||||
}
|
||||
|
||||
~CMatrix()
|
||||
{
|
||||
}
|
||||
|
||||
void Translate(double offsetX, double offsetY, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_translation(offsetX, offsetY));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_translation(offsetX, offsetY));
|
||||
}
|
||||
}
|
||||
|
||||
void Scale(double scaleX, double scaleY, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_scaling(scaleX, scaleY));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_scaling(scaleX, scaleY));
|
||||
}
|
||||
}
|
||||
|
||||
void Shear(double shearX, double shearY, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_skewing(shearX, shearY));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_skewing(shearX, shearY));
|
||||
}
|
||||
}
|
||||
|
||||
void TransformPoint(double& x, double& y)
|
||||
{
|
||||
m_agg_mtx.transform(&x, &y);
|
||||
}
|
||||
|
||||
void Rotate(double angle, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
}
|
||||
|
||||
void RotateAt(double angle, double x, double y, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
Translate(-x, -y, order);
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
Translate(x, y, order);
|
||||
}
|
||||
|
||||
void Multiply(const CMatrix* matrix, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
if (order == Aggplus::MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(matrix->m_agg_mtx);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(matrix->m_agg_mtx);
|
||||
}
|
||||
}
|
||||
|
||||
double OffsetX() const
|
||||
{
|
||||
double M[6]; m_agg_mtx.store_to(M);
|
||||
return (M[4]);
|
||||
}
|
||||
double OffsetY() const
|
||||
{
|
||||
double M[6]; m_agg_mtx.store_to(M);
|
||||
return (M[5]);
|
||||
}
|
||||
|
||||
bool GetElements(float* m) const
|
||||
{
|
||||
double M[6]; m_agg_mtx.store_to(M);
|
||||
m[0]=(float)M[0];
|
||||
m[1]=(float)M[1];
|
||||
m[2]=(float)M[2];
|
||||
m[3]=(float)M[3];
|
||||
m[4]=(float)M[4];
|
||||
m[5]=(float)M[5];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetElements(double* m) const
|
||||
{
|
||||
m_agg_mtx.store_to(m);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_agg_mtx.reset();
|
||||
}
|
||||
|
||||
const CMatrix& operator=(const CMatrix& Src)
|
||||
{
|
||||
m_agg_mtx = Src.m_agg_mtx;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Invert()
|
||||
{
|
||||
double d = m_agg_mtx.determinant();
|
||||
if (0.0001 >= abs(d))
|
||||
return false;
|
||||
|
||||
m_agg_mtx.invert();
|
||||
return true;
|
||||
}
|
||||
|
||||
//Temp
|
||||
//Used in X_BrushLinearGradient constructor
|
||||
double z_Rotation() const
|
||||
{
|
||||
return agg::rad2deg(m_agg_mtx.rotation());
|
||||
}
|
||||
|
||||
__forceinline void SetElements(const double& m11, const double& m12, const double& m21, const double& m22, const double& dx, const double& dy)
|
||||
{
|
||||
m_agg_mtx.sx = m11;
|
||||
m_agg_mtx.shy = m12;
|
||||
m_agg_mtx.shx = m21;
|
||||
m_agg_mtx.sy = m22;
|
||||
m_agg_mtx.tx = dx;
|
||||
m_agg_mtx.ty = dy;
|
||||
}
|
||||
|
||||
public:
|
||||
agg::trans_affine m_agg_mtx;
|
||||
};
|
||||
}
|
||||
704
AVSEBOOKWriter2/Common/StringWriter.h
Normal file
704
AVSEBOOKWriter2/Common/StringWriter.h
Normal file
@ -0,0 +1,704 @@
|
||||
#pragma once
|
||||
#include "File.h"
|
||||
|
||||
const double c_ag_Inch_to_MM = 25.4;
|
||||
const double c_ag_1pxWidth = 25.4 / 96;
|
||||
|
||||
static wchar_t g_wc_amp = wchar_t('&');
|
||||
static wchar_t g_wc_apos = wchar_t('\'');
|
||||
static wchar_t g_wc_lt = wchar_t('<');
|
||||
static wchar_t g_wc_qt = wchar_t('>');
|
||||
static wchar_t g_wc_quot = wchar_t('\"');
|
||||
|
||||
static _bstr_t g_bstr_amp = L"&";
|
||||
static _bstr_t g_bstr_apos = L"'";
|
||||
static _bstr_t g_bstr_lt = L"<";
|
||||
static _bstr_t g_bstr_qt = L">";
|
||||
static _bstr_t g_bstr_quot = L"\"";
|
||||
static _bstr_t g_bstr_mdash = L"—";
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
enum ImageType
|
||||
{
|
||||
itJPG = 0,
|
||||
itPNG = 1
|
||||
};
|
||||
class CImageInfo
|
||||
{
|
||||
public:
|
||||
ImageType m_eType;
|
||||
LONG m_lID;
|
||||
|
||||
CImageInfo()
|
||||
{
|
||||
m_eType = itJPG;
|
||||
m_lID = -1;
|
||||
}
|
||||
CImageInfo(const CImageInfo& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CImageInfo& operator=(const CImageInfo& oSrc)
|
||||
{
|
||||
m_eType = oSrc.m_eType;
|
||||
m_lID = oSrc.m_lID;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
AVSINLINE CString GetPath(const CString& strMedia)
|
||||
{
|
||||
CString strExt = _T("");
|
||||
strExt.Format(_T("\\image%d.%s"), m_lID, (itJPG == m_eType) ? _T("jpg") : _T("png"));
|
||||
return strMedia + strExt;
|
||||
}
|
||||
};
|
||||
|
||||
inline static double FABS(double dVal)
|
||||
{
|
||||
return (dVal >= 0) ? dVal : -dVal;
|
||||
}
|
||||
inline static int round(double dVal)
|
||||
{
|
||||
return (int)(dVal + 0.5);
|
||||
}
|
||||
|
||||
class CBufferedText
|
||||
{
|
||||
protected:
|
||||
BYTE* m_pData;
|
||||
size_t m_lSize;
|
||||
|
||||
BYTE* m_pDataCur;
|
||||
size_t m_lSizeCur;
|
||||
|
||||
public:
|
||||
CBufferedText()
|
||||
{
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = m_lSize;
|
||||
}
|
||||
CBufferedText(const CBufferedText& oSrc)
|
||||
{
|
||||
m_pData = NULL;
|
||||
*this = oSrc;
|
||||
}
|
||||
CBufferedText& operator=(const CBufferedText& oSrc)
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_lSize = oSrc.m_lSize;
|
||||
m_lSizeCur = oSrc.m_lSizeCur;
|
||||
m_pData = (BYTE*)malloc(m_lSize * sizeof(BYTE));
|
||||
|
||||
memcpy(m_pData, oSrc.m_pData, m_lSizeCur * sizeof(BYTE));
|
||||
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CBufferedText(const size_t& nLen)
|
||||
{
|
||||
m_lSize = nLen;
|
||||
m_pData = (BYTE*)malloc(m_lSize * sizeof(BYTE));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
}
|
||||
virtual ~CBufferedText()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
}
|
||||
|
||||
AVSINLINE void AddSize(const size_t& nSize)
|
||||
{
|
||||
if (NULL == m_pData)
|
||||
{
|
||||
m_lSize = max(nSize, 1000);
|
||||
m_pData = (BYTE*)malloc(m_lSize * sizeof(BYTE));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
while ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
m_lSize *= 2;
|
||||
}
|
||||
|
||||
BYTE* pRealloc = (BYTE*)realloc(m_pData, m_lSize * sizeof(BYTE));
|
||||
if (NULL != pRealloc)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
m_pData = pRealloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
else
|
||||
{
|
||||
BYTE* pMalloc = (BYTE*)malloc(m_lSize * sizeof(BYTE));
|
||||
memcpy(pMalloc, m_pData, m_lSizeCur * sizeof(BYTE));
|
||||
|
||||
free(m_pData);
|
||||
m_pData = pMalloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
AVSINLINE BYTE operator[](const size_t& nIndex)
|
||||
{
|
||||
if (nIndex < m_lSizeCur)
|
||||
return m_pData[nIndex];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
AVSINLINE void WriteData(BYTE* pString, const size_t& nLen)
|
||||
{
|
||||
AddSize(nLen);
|
||||
memcpy(m_pDataCur, pString, nLen);
|
||||
m_pDataCur += nLen;
|
||||
m_lSizeCur += nLen;
|
||||
}
|
||||
AVSINLINE BYTE* GetData()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
AVSINLINE size_t GetCurSize()
|
||||
{
|
||||
return m_lSizeCur;
|
||||
}
|
||||
AVSINLINE size_t GetSize()
|
||||
{
|
||||
return m_lSize;
|
||||
}
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
AVSINLINE void ClearNoAttack()
|
||||
{
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class CTextItem
|
||||
{
|
||||
protected:
|
||||
wchar_t* m_pData;
|
||||
size_t m_lSize;
|
||||
|
||||
wchar_t* m_pDataCur;
|
||||
size_t m_lSizeCur;
|
||||
|
||||
public:
|
||||
CTextItem()
|
||||
{
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = m_lSize;
|
||||
}
|
||||
CTextItem(const CTextItem& oSrc)
|
||||
{
|
||||
m_pData = NULL;
|
||||
*this = oSrc;
|
||||
}
|
||||
CTextItem& operator=(const CTextItem& oSrc)
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_lSize = oSrc.m_lSize;
|
||||
m_lSizeCur = oSrc.m_lSizeCur;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
memcpy(m_pData, oSrc.m_pData, m_lSizeCur * sizeof(wchar_t));
|
||||
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CTextItem(const size_t& nLen)
|
||||
{
|
||||
m_lSize = nLen;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
}
|
||||
CTextItem(wchar_t* pData, const size_t& nLen)
|
||||
{
|
||||
m_lSize = nLen;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
memcpy(m_pData, pData, m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = m_lSize;
|
||||
m_pDataCur = m_pData + m_lSize;
|
||||
}
|
||||
CTextItem(wchar_t* pData, BYTE* pUnicodeChecker = NULL)
|
||||
{
|
||||
size_t nLen = GetStringLen(pData);
|
||||
|
||||
m_lSize = nLen;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
memcpy(m_pData, pData, m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = m_lSize;
|
||||
m_pDataCur = m_pData + m_lSize;
|
||||
|
||||
if (NULL != pUnicodeChecker)
|
||||
{
|
||||
wchar_t* pMemory = m_pData;
|
||||
while (pMemory < m_pDataCur)
|
||||
{
|
||||
if (!pUnicodeChecker[*pMemory])
|
||||
*pMemory = wchar_t(' ');
|
||||
++pMemory;
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual ~CTextItem()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
}
|
||||
|
||||
AVSINLINE void AddSize(const size_t& nSize)
|
||||
{
|
||||
if (NULL == m_pData)
|
||||
{
|
||||
m_lSize = max(nSize, 1000);
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
while ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
m_lSize *= 2;
|
||||
}
|
||||
|
||||
wchar_t* pRealloc = (wchar_t*)realloc(m_pData, m_lSize * sizeof(wchar_t));
|
||||
if (NULL != pRealloc)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
m_pData = pRealloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t* pMalloc = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
memcpy(pMalloc, m_pData, m_lSizeCur * sizeof(wchar_t));
|
||||
|
||||
free(m_pData);
|
||||
m_pData = pMalloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AVSINLINE wchar_t* GetData()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
AVSINLINE size_t GetCurSize()
|
||||
{
|
||||
return m_lSizeCur;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
AVSINLINE void operator+=(const CTextItem& oTemp)
|
||||
{
|
||||
WriteString(oTemp.m_pData, oTemp.m_lSizeCur);
|
||||
}
|
||||
AVSINLINE void operator+=(_bstr_t& oTemp)
|
||||
{
|
||||
size_t nLen = oTemp.length();
|
||||
WriteString(oTemp.GetBSTR(), nLen);
|
||||
}
|
||||
AVSINLINE void operator+=(CString& oTemp)
|
||||
{
|
||||
size_t nLen = (size_t)oTemp.GetLength();
|
||||
|
||||
#ifdef _UNICODE
|
||||
WriteString(oTemp.GetBuffer(), nLen);
|
||||
#else
|
||||
CStringW str = (CStringW)oTemp;
|
||||
WriteString(str.GetBuffer(), nLen);
|
||||
#endif
|
||||
}
|
||||
AVSINLINE wchar_t& operator[](const size_t& nIndex)
|
||||
{
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
AVSINLINE void SetText(BSTR& bsText)
|
||||
{
|
||||
ClearNoAttack();
|
||||
size_t nLen = GetStringLen(bsText);
|
||||
|
||||
WriteString(bsText, nLen);
|
||||
}
|
||||
AVSINLINE void AddSpace()
|
||||
{
|
||||
AddSize(1);
|
||||
*m_pDataCur = wchar_t(' ');
|
||||
|
||||
++m_lSizeCur;
|
||||
++m_pDataCur;
|
||||
}
|
||||
AVSINLINE void AddSpaceFirst()
|
||||
{
|
||||
AddSize(1);
|
||||
|
||||
wchar_t* pMemory = new wchar_t[m_lSizeCur];
|
||||
memcpy(pMemory, m_pData, m_lSizeCur * sizeof(wchar_t));
|
||||
memcpy(m_pData + 1, pMemory, m_lSizeCur * sizeof(wchar_t));
|
||||
RELEASEARRAYOBJECTS(pMemory);
|
||||
|
||||
*m_pData = wchar_t(' ');
|
||||
|
||||
++m_lSizeCur;
|
||||
++m_pDataCur;
|
||||
}
|
||||
AVSINLINE void CorrectUnicode(const BYTE* pUnicodeChecker)
|
||||
{
|
||||
if (NULL != pUnicodeChecker)
|
||||
{
|
||||
wchar_t* pMemory = m_pData;
|
||||
while (pMemory < m_pDataCur)
|
||||
{
|
||||
if (!pUnicodeChecker[*pMemory])
|
||||
*pMemory = wchar_t(' ');
|
||||
++pMemory;
|
||||
}
|
||||
}
|
||||
}
|
||||
AVSINLINE void RemoveLastSpaces()
|
||||
{
|
||||
wchar_t* pMemory = m_pDataCur - 1;
|
||||
while ((pMemory > m_pData) && (wchar_t(' ') == *pMemory))
|
||||
{
|
||||
--pMemory;
|
||||
--m_lSizeCur;
|
||||
--m_pDataCur;
|
||||
}
|
||||
|
||||
}
|
||||
AVSINLINE bool IsSpace()
|
||||
{
|
||||
if (1 != m_lSizeCur)
|
||||
return false;
|
||||
return (wchar_t(' ') == *m_pData);
|
||||
}
|
||||
AVSINLINE void CheckLastSpanLine()
|
||||
{
|
||||
if (0 == m_lSizeCur)
|
||||
return;
|
||||
|
||||
if ((wchar_t(' ') == m_pData[m_lSizeCur - 1]) || (wchar_t('-') == m_pData[m_lSizeCur - 1]))
|
||||
return;
|
||||
|
||||
AddSpace();
|
||||
}
|
||||
|
||||
public:
|
||||
AVSINLINE void WriteString(wchar_t* pString, const size_t& nLen)
|
||||
{
|
||||
AddSize(nLen);
|
||||
//memcpy(m_pDataCur, pString, nLen * sizeof(wchar_t));
|
||||
memcpy(m_pDataCur, pString, nLen << 1);
|
||||
m_pDataCur += nLen;
|
||||
m_lSizeCur += nLen;
|
||||
}
|
||||
AVSINLINE size_t GetSize()
|
||||
{
|
||||
return m_lSize;
|
||||
}
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
AVSINLINE void ClearNoAttack()
|
||||
{
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
|
||||
AVSINLINE size_t GetStringLen(wchar_t* pData)
|
||||
{
|
||||
wchar_t* s = pData;
|
||||
for (; *s != 0; ++s);
|
||||
return (size_t)(s - pData);
|
||||
}
|
||||
|
||||
AVSINLINE CString GetCString()
|
||||
{
|
||||
CString str(m_pData, (int)m_lSizeCur);
|
||||
return str;
|
||||
}
|
||||
AVSINLINE wchar_t* GetBuffer()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
};
|
||||
|
||||
class CStringWriter : public CTextItem
|
||||
{
|
||||
public:
|
||||
CStringWriter() : CTextItem()
|
||||
{
|
||||
}
|
||||
virtual ~CStringWriter()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
AVSINLINE void WriteStringB(_bstr_t& bsString)
|
||||
{
|
||||
size_t nLen = bsString.length();
|
||||
CTextItem::WriteString(bsString.GetBSTR(), nLen);
|
||||
}
|
||||
AVSINLINE void WriteString(CString sString)
|
||||
{
|
||||
size_t nLen = (size_t)sString.GetLength();
|
||||
|
||||
#ifdef _UNICODE
|
||||
CTextItem::WriteString(sString.GetBuffer(), nLen);
|
||||
#else
|
||||
CStringW str = (CStringW)sString;
|
||||
WriteString(str.GetBuffer(), nLen);
|
||||
#endif
|
||||
}
|
||||
AVSINLINE void WriteStringC(const CString& sString)
|
||||
{
|
||||
size_t nLen = (size_t)sString.GetLength();
|
||||
|
||||
CString* pStr = const_cast<CString*>(&sString);
|
||||
|
||||
#ifdef _UNICODE
|
||||
CTextItem::WriteString(pStr->GetBuffer(), nLen);
|
||||
#else
|
||||
CStringW str = (CStringW)sString;
|
||||
WriteString(str.GetBuffer(), nLen);
|
||||
#endif
|
||||
}
|
||||
AVSINLINE void Write(CStringWriter& oWriter)
|
||||
{
|
||||
CTextItem::WriteString(oWriter.m_pData, oWriter.m_lSizeCur);
|
||||
}
|
||||
AVSINLINE void WriteI(CTextItem& oItem)
|
||||
{
|
||||
CTextItem::WriteString(oItem.GetData(), oItem.GetCurSize());
|
||||
}
|
||||
|
||||
AVSINLINE void WriteString(wchar_t* pString, const size_t& nLen)
|
||||
{
|
||||
CTextItem::AddSize(nLen);
|
||||
//memcpy(m_pDataCur, pString, nLen * sizeof(wchar_t));
|
||||
memcpy(m_pDataCur, pString, nLen << 1);
|
||||
m_pDataCur += nLen;
|
||||
m_lSizeCur += nLen;
|
||||
}
|
||||
|
||||
void WriteTextHTML(CTextItem& oItem)
|
||||
{
|
||||
size_t nCurrent = 0;
|
||||
size_t nCount = oItem.GetCurSize();
|
||||
|
||||
size_t nCurrentOld = nCurrent;
|
||||
wchar_t* pData = oItem.GetData();
|
||||
wchar_t* pStartData = pData;
|
||||
|
||||
while (nCurrent < nCount)
|
||||
{
|
||||
wchar_t c = *pData++;
|
||||
|
||||
if (g_wc_amp == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_amp);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
/*else if (g_wc_apos == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_apos);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}*/
|
||||
else if (g_wc_lt == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_lt);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else if (g_wc_qt == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_qt);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else if (g_wc_quot == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_quot);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else if (8212 == (USHORT)c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_mdash);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else
|
||||
{
|
||||
++nCurrent;
|
||||
}
|
||||
}
|
||||
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
}
|
||||
|
||||
void WriteTextXML(CTextItem& oItem)
|
||||
{
|
||||
size_t nCurrent = 0;
|
||||
size_t nCount = oItem.GetCurSize();
|
||||
|
||||
size_t nCurrentOld = nCurrent;
|
||||
wchar_t* pData = oItem.GetData();
|
||||
wchar_t* pStartData = pData;
|
||||
|
||||
while (nCurrent < nCount)
|
||||
{
|
||||
wchar_t c = *pData++;
|
||||
|
||||
if (g_wc_amp == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_amp);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
/*else if (g_wc_apos == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_apos);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}*/
|
||||
else if (g_wc_lt == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_lt);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else if (g_wc_qt == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_qt);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else if (g_wc_quot == c)
|
||||
{
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
|
||||
WriteStringB(g_bstr_quot);
|
||||
|
||||
++nCurrent;
|
||||
nCurrentOld = nCurrent;
|
||||
pStartData = pData;
|
||||
}
|
||||
else
|
||||
{
|
||||
++nCurrent;
|
||||
}
|
||||
}
|
||||
|
||||
if (nCurrentOld != nCurrent)
|
||||
WriteString(pStartData, nCurrent - nCurrentOld);
|
||||
}
|
||||
};
|
||||
}
|
||||
180
AVSEBOOKWriter2/Common/agg_trans_affine.cpp
Normal file
180
AVSEBOOKWriter2/Common/agg_trans_affine.cpp
Normal file
@ -0,0 +1,180 @@
|
||||
//
|
||||
// Affine transformations
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "agg_trans_affine.h"
|
||||
|
||||
|
||||
namespace agg
|
||||
{
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::parl_to_parl(const double* src,
|
||||
const double* dst)
|
||||
{
|
||||
sx = src[2] - src[0];
|
||||
shy = src[3] - src[1];
|
||||
shx = src[4] - src[0];
|
||||
sy = src[5] - src[1];
|
||||
tx = src[0];
|
||||
ty = src[1];
|
||||
invert();
|
||||
multiply(trans_affine(dst[2] - dst[0], dst[3] - dst[1],
|
||||
dst[4] - dst[0], dst[5] - dst[1],
|
||||
dst[0], dst[1]));
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::rect_to_parl(double x1, double y1,
|
||||
double x2, double y2,
|
||||
const double* parl)
|
||||
{
|
||||
double src[6];
|
||||
src[0] = x1; src[1] = y1;
|
||||
src[2] = x2; src[3] = y1;
|
||||
src[4] = x2; src[5] = y2;
|
||||
parl_to_parl(src, parl);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::parl_to_rect(const double* parl,
|
||||
double x1, double y1,
|
||||
double x2, double y2)
|
||||
{
|
||||
double dst[6];
|
||||
dst[0] = x1; dst[1] = y1;
|
||||
dst[2] = x2; dst[3] = y1;
|
||||
dst[4] = x2; dst[5] = y2;
|
||||
parl_to_parl(parl, dst);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::multiply(const trans_affine& m)
|
||||
{
|
||||
double t0 = sx * m.sx + shy * m.shx;
|
||||
double t2 = shx * m.sx + sy * m.shx;
|
||||
double t4 = tx * m.sx + ty * m.shx + m.tx;
|
||||
shy = sx * m.shy + shy * m.sy;
|
||||
sy = shx * m.shy + sy * m.sy;
|
||||
ty = tx * m.shy + ty * m.sy + m.ty;
|
||||
sx = t0;
|
||||
shx = t2;
|
||||
tx = t4;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::invert()
|
||||
{
|
||||
double d = determinant_reciprocal();
|
||||
|
||||
double t0 = sy * d;
|
||||
sy = sx * d;
|
||||
shy = -shy * d;
|
||||
shx = -shx * d;
|
||||
|
||||
double t4 = -tx * t0 - ty * shx;
|
||||
ty = -tx * shy - ty * sy;
|
||||
|
||||
sx = t0;
|
||||
tx = t4;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::flip_x()
|
||||
{
|
||||
sx = -sx;
|
||||
shy = -shy;
|
||||
tx = -tx;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::flip_y()
|
||||
{
|
||||
shx = -shx;
|
||||
sy = -sy;
|
||||
ty = -ty;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
const trans_affine& trans_affine::reset()
|
||||
{
|
||||
sx = sy = 1.0;
|
||||
shy = shx = tx = ty = 0.0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
bool trans_affine::is_identity(double epsilon) const
|
||||
{
|
||||
return is_equal_eps(sx, 1.0, epsilon) &&
|
||||
is_equal_eps(shy, 0.0, epsilon) &&
|
||||
is_equal_eps(shx, 0.0, epsilon) &&
|
||||
is_equal_eps(sy, 1.0, epsilon) &&
|
||||
is_equal_eps(tx, 0.0, epsilon) &&
|
||||
is_equal_eps(ty, 0.0, epsilon);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
bool trans_affine::is_valid(double epsilon) const
|
||||
{
|
||||
return fabs(sx) > epsilon && fabs(sy) > epsilon;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
bool trans_affine::is_equal(const trans_affine& m, double epsilon) const
|
||||
{
|
||||
return is_equal_eps(sx, m.sx, epsilon) &&
|
||||
is_equal_eps(shy, m.shy, epsilon) &&
|
||||
is_equal_eps(shx, m.shx, epsilon) &&
|
||||
is_equal_eps(sy, m.sy, epsilon) &&
|
||||
is_equal_eps(tx, m.tx, epsilon) &&
|
||||
is_equal_eps(ty, m.ty, epsilon);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
double trans_affine::rotation() const
|
||||
{
|
||||
double x1 = 0.0;
|
||||
double y1 = 0.0;
|
||||
double x2 = 1.0;
|
||||
double y2 = 0.0;
|
||||
transform(&x1, &y1);
|
||||
transform(&x2, &y2);
|
||||
return atan2(y2-y1, x2-x1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void trans_affine::translation(double* dx, double* dy) const
|
||||
{
|
||||
*dx = tx;
|
||||
*dy = ty;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void trans_affine::scaling(double* x, double* y) const
|
||||
{
|
||||
double x1 = 0.0;
|
||||
double y1 = 0.0;
|
||||
double x2 = 1.0;
|
||||
double y2 = 1.0;
|
||||
trans_affine t(*this);
|
||||
t *= trans_affine_rotation(-rotation());
|
||||
t.transform(&x1, &y1);
|
||||
t.transform(&x2, &y2);
|
||||
*x = x2 - x1;
|
||||
*y = y2 - y1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
515
AVSEBOOKWriter2/Common/agg_trans_affine.h
Normal file
515
AVSEBOOKWriter2/Common/agg_trans_affine.h
Normal file
@ -0,0 +1,515 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef _USE_MATH_DEFINES
|
||||
#define _USE_MATH_DEFINES
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
namespace agg
|
||||
{
|
||||
const double affine_epsilon = 1e-14;
|
||||
|
||||
//------------------------------------------------------------is_equal_eps
|
||||
template<class T> inline bool is_equal_eps(T v1, T v2, T epsilon)
|
||||
{
|
||||
return fabs(v1 - v2) <= double(epsilon);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------deg2rad
|
||||
inline double deg2rad(double deg)
|
||||
{
|
||||
return deg * M_PI / 180.0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------rad2deg
|
||||
inline double rad2deg(double rad)
|
||||
{
|
||||
return rad * 180.0 / M_PI;
|
||||
}
|
||||
|
||||
//============================================================trans_affine
|
||||
//
|
||||
// See Implementation agg_trans_affine.cpp
|
||||
//
|
||||
// Affine transformation are linear transformations in Cartesian coordinates
|
||||
// (strictly speaking not only in Cartesian, but for the beginning we will
|
||||
// think so). They are rotation, scaling, translation and skewing.
|
||||
// After any affine transformation a line segment remains a line segment
|
||||
// and it will never become a curve.
|
||||
//
|
||||
// There will be no math about matrix calculations, since it has been
|
||||
// described many times. Ask yourself a very simple question:
|
||||
// "why do we need to understand and use some matrix stuff instead of just
|
||||
// rotating, scaling and so on". The answers are:
|
||||
//
|
||||
// 1. Any combination of transformations can be done by only 4 multiplications
|
||||
// and 4 additions in floating point.
|
||||
// 2. One matrix transformation is equivalent to the number of consecutive
|
||||
// discrete transformations, i.e. the matrix "accumulates" all transformations
|
||||
// in the order of their settings. Suppose we have 4 transformations:
|
||||
// * rotate by 30 degrees,
|
||||
// * scale X to 2.0,
|
||||
// * scale Y to 1.5,
|
||||
// * move to (100, 100).
|
||||
// The result will depend on the order of these transformations,
|
||||
// and the advantage of matrix is that the sequence of discret calls:
|
||||
// rotate(30), scaleX(2.0), scaleY(1.5), move(100,100)
|
||||
// will have exactly the same result as the following matrix transformations:
|
||||
//
|
||||
// affine_matrix m;
|
||||
// m *= rotate_matrix(30);
|
||||
// m *= scaleX_matrix(2.0);
|
||||
// m *= scaleY_matrix(1.5);
|
||||
// m *= move_matrix(100,100);
|
||||
//
|
||||
// m.transform_my_point_at_last(x, y);
|
||||
//
|
||||
// What is the good of it? In real life we will set-up the matrix only once
|
||||
// and then transform many points, let alone the convenience to set any
|
||||
// combination of transformations.
|
||||
//
|
||||
// So, how to use it? Very easy - literally as it's shown above. Not quite,
|
||||
// let us write a correct example:
|
||||
//
|
||||
// agg::trans_affine m;
|
||||
// m *= agg::trans_affine_rotation(30.0 * 3.1415926 / 180.0);
|
||||
// m *= agg::trans_affine_scaling(2.0, 1.5);
|
||||
// m *= agg::trans_affine_translation(100.0, 100.0);
|
||||
// m.transform(&x, &y);
|
||||
//
|
||||
// The affine matrix is all you need to perform any linear transformation,
|
||||
// but all transformations have origin point (0,0). It means that we need to
|
||||
// use 2 translations if we want to rotate someting around (100,100):
|
||||
//
|
||||
// m *= agg::trans_affine_translation(-100.0, -100.0); // move to (0,0)
|
||||
// m *= agg::trans_affine_rotation(30.0 * 3.1415926 / 180.0); // rotate
|
||||
// m *= agg::trans_affine_translation(100.0, 100.0); // move back to (100,100)
|
||||
//----------------------------------------------------------------------
|
||||
struct trans_affine
|
||||
{
|
||||
double sx, shy, shx, sy, tx, ty;
|
||||
|
||||
//------------------------------------------ Construction
|
||||
// Identity matrix
|
||||
trans_affine() :
|
||||
sx(1.0), shy(0.0), shx(0.0), sy(1.0), tx(0.0), ty(0.0)
|
||||
{}
|
||||
|
||||
// Custom matrix. Usually used in derived classes
|
||||
trans_affine(double v0, double v1, double v2,
|
||||
double v3, double v4, double v5) :
|
||||
sx(v0), shy(v1), shx(v2), sy(v3), tx(v4), ty(v5)
|
||||
{}
|
||||
|
||||
// Custom matrix from m[6]
|
||||
explicit trans_affine(const double* m) :
|
||||
sx(m[0]), shy(m[1]), shx(m[2]), sy(m[3]), tx(m[4]), ty(m[5])
|
||||
{}
|
||||
|
||||
// Rectangle to a parallelogram.
|
||||
trans_affine(double x1, double y1, double x2, double y2,
|
||||
const double* parl)
|
||||
{
|
||||
rect_to_parl(x1, y1, x2, y2, parl);
|
||||
}
|
||||
|
||||
// Parallelogram to a rectangle.
|
||||
trans_affine(const double* parl,
|
||||
double x1, double y1, double x2, double y2)
|
||||
{
|
||||
parl_to_rect(parl, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
// Arbitrary parallelogram transformation.
|
||||
trans_affine(const double* src, const double* dst)
|
||||
{
|
||||
parl_to_parl(src, dst);
|
||||
}
|
||||
|
||||
//---------------------------------- Parellelogram transformations
|
||||
// transform a parallelogram to another one. Src and dst are
|
||||
// pointers to arrays of three points (double[6], x1,y1,...) that
|
||||
// identify three corners of the parallelograms assuming implicit
|
||||
// fourth point. The arguments are arrays of double[6] mapped
|
||||
// to x1,y1, x2,y2, x3,y3 where the coordinates are:
|
||||
// *-----------------*
|
||||
// / (x3,y3)/
|
||||
// / /
|
||||
// /(x1,y1) (x2,y2)/
|
||||
// *-----------------*
|
||||
const trans_affine& parl_to_parl(const double* src,
|
||||
const double* dst);
|
||||
|
||||
const trans_affine& rect_to_parl(double x1, double y1,
|
||||
double x2, double y2,
|
||||
const double* parl);
|
||||
|
||||
const trans_affine& parl_to_rect(const double* parl,
|
||||
double x1, double y1,
|
||||
double x2, double y2);
|
||||
|
||||
|
||||
//------------------------------------------ Operations
|
||||
// Reset - load an identity matrix
|
||||
const trans_affine& reset();
|
||||
|
||||
// Direct transformations operations
|
||||
const trans_affine& translate(double x, double y);
|
||||
const trans_affine& rotate(double a);
|
||||
const trans_affine& scale(double s);
|
||||
const trans_affine& scale(double x, double y);
|
||||
|
||||
// Multiply matrix to another one
|
||||
const trans_affine& multiply(const trans_affine& m);
|
||||
|
||||
// Multiply "m" to "this" and assign the result to "this"
|
||||
const trans_affine& premultiply(const trans_affine& m);
|
||||
|
||||
// Multiply matrix to inverse of another one
|
||||
const trans_affine& multiply_inv(const trans_affine& m);
|
||||
|
||||
// Multiply inverse of "m" to "this" and assign the result to "this"
|
||||
const trans_affine& premultiply_inv(const trans_affine& m);
|
||||
|
||||
// Invert matrix. Do not try to invert degenerate matrices,
|
||||
// there's no check for validity. If you set scale to 0 and
|
||||
// then try to invert matrix, expect unpredictable result.
|
||||
const trans_affine& invert();
|
||||
|
||||
// Mirroring around X
|
||||
const trans_affine& flip_x();
|
||||
|
||||
// Mirroring around Y
|
||||
const trans_affine& flip_y();
|
||||
|
||||
//------------------------------------------- Load/Store
|
||||
// Store matrix to an array [6] of double
|
||||
void store_to(double* m) const
|
||||
{
|
||||
*m++ = sx; *m++ = shy; *m++ = shx; *m++ = sy; *m++ = tx; *m++ = ty;
|
||||
}
|
||||
|
||||
// Load matrix from an array [6] of double
|
||||
const trans_affine& load_from(const double* m)
|
||||
{
|
||||
sx = *m++; shy = *m++; shx = *m++; sy = *m++; tx = *m++; ty = *m++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------- Operators
|
||||
|
||||
// Multiply the matrix by another one
|
||||
const trans_affine& operator *= (const trans_affine& m)
|
||||
{
|
||||
return multiply(m);
|
||||
}
|
||||
|
||||
// Multiply the matrix by inverse of another one
|
||||
const trans_affine& operator /= (const trans_affine& m)
|
||||
{
|
||||
return multiply_inv(m);
|
||||
}
|
||||
|
||||
// Multiply the matrix by another one and return
|
||||
// the result in a separete matrix.
|
||||
trans_affine operator * (const trans_affine& m)
|
||||
{
|
||||
return trans_affine(*this).multiply(m);
|
||||
}
|
||||
|
||||
// Multiply the matrix by inverse of another one
|
||||
// and return the result in a separete matrix.
|
||||
trans_affine operator / (const trans_affine& m)
|
||||
{
|
||||
return trans_affine(*this).multiply_inv(m);
|
||||
}
|
||||
|
||||
// Calculate and return the inverse matrix
|
||||
trans_affine operator ~ () const
|
||||
{
|
||||
trans_affine ret = *this;
|
||||
return ret.invert();
|
||||
}
|
||||
|
||||
// Equal operator with default epsilon
|
||||
bool operator == (const trans_affine& m) const
|
||||
{
|
||||
return is_equal(m, affine_epsilon);
|
||||
}
|
||||
|
||||
// Not Equal operator with default epsilon
|
||||
bool operator != (const trans_affine& m) const
|
||||
{
|
||||
return !is_equal(m, affine_epsilon);
|
||||
}
|
||||
|
||||
//-------------------------------------------- Transformations
|
||||
// Direct transformation of x and y
|
||||
void transform(double* x, double* y) const;
|
||||
|
||||
// Direct transformation of x and y, 2x2 matrix only, no translation
|
||||
void transform_2x2(double* x, double* y) const;
|
||||
|
||||
// Inverse transformation of x and y. It works slower than the
|
||||
// direct transformation. For massive operations it's better to
|
||||
// invert() the matrix and then use direct transformations.
|
||||
void inverse_transform(double* x, double* y) const;
|
||||
|
||||
//-------------------------------------------- Auxiliary
|
||||
// Calculate the determinant of matrix
|
||||
double determinant() const
|
||||
{
|
||||
return sx * sy - shy * shx;
|
||||
}
|
||||
|
||||
// Calculate the reciprocal of the determinant
|
||||
double determinant_reciprocal() const
|
||||
{
|
||||
return 1.0 / (sx * sy - shy * shx);
|
||||
}
|
||||
|
||||
// Get the average scale (by X and Y).
|
||||
// Basically used to calculate the approximation_scale when
|
||||
// decomposinting curves into line segments.
|
||||
double scale() const;
|
||||
|
||||
// Check to see if the matrix is not degenerate
|
||||
bool is_valid(double epsilon = affine_epsilon) const;
|
||||
|
||||
// Check to see if it's an identity matrix
|
||||
bool is_identity(double epsilon = affine_epsilon) const;
|
||||
|
||||
// Check to see if two matrices are equal
|
||||
bool is_equal(const trans_affine& m, double epsilon = affine_epsilon) const;
|
||||
|
||||
// Determine the major parameters. Use with caution considering
|
||||
// possible degenerate cases.
|
||||
double rotation() const;
|
||||
void translation(double* dx, double* dy) const;
|
||||
void scaling(double* x, double* y) const;
|
||||
void scaling_abs(double* x, double* y) const;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline void trans_affine::transform(double* x, double* y) const
|
||||
{
|
||||
register double tmp = *x;
|
||||
*x = tmp * sx + *y * shx + tx;
|
||||
*y = tmp * shy + *y * sy + ty;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline void trans_affine::transform_2x2(double* x, double* y) const
|
||||
{
|
||||
register double tmp = *x;
|
||||
*x = tmp * sx + *y * shx;
|
||||
*y = tmp * shy + *y * sy;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline void trans_affine::inverse_transform(double* x, double* y) const
|
||||
{
|
||||
register double d = determinant_reciprocal();
|
||||
register double a = (*x - tx) * d;
|
||||
register double b = (*y - ty) * d;
|
||||
*x = a * sy - b * shx;
|
||||
*y = b * sx - a * shy;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline double trans_affine::scale() const
|
||||
{
|
||||
double x = 0.707106781 * sx + 0.707106781 * shx;
|
||||
double y = 0.707106781 * shy + 0.707106781 * sy;
|
||||
return sqrt(x*x + y*y);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::translate(double x, double y)
|
||||
{
|
||||
tx += x;
|
||||
ty += y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::rotate(double a)
|
||||
{
|
||||
double ca = cos(a);
|
||||
double sa = sin(a);
|
||||
double t0 = sx * ca - shy * sa;
|
||||
double t2 = shx * ca - sy * sa;
|
||||
double t4 = tx * ca - ty * sa;
|
||||
shy = sx * sa + shy * ca;
|
||||
sy = shx * sa + sy * ca;
|
||||
ty = tx * sa + ty * ca;
|
||||
sx = t0;
|
||||
shx = t2;
|
||||
tx = t4;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::scale(double x, double y)
|
||||
{
|
||||
double mm0 = x; // Possible hint for the optimizer
|
||||
double mm3 = y;
|
||||
sx *= mm0;
|
||||
shx *= mm0;
|
||||
tx *= mm0;
|
||||
shy *= mm3;
|
||||
sy *= mm3;
|
||||
ty *= mm3;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::scale(double s)
|
||||
{
|
||||
double m = s; // Possible hint for the optimizer
|
||||
sx *= m;
|
||||
shx *= m;
|
||||
tx *= m;
|
||||
shy *= m;
|
||||
sy *= m;
|
||||
ty *= m;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::premultiply(const trans_affine& m)
|
||||
{
|
||||
trans_affine t = m;
|
||||
return *this = t.multiply(*this);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::multiply_inv(const trans_affine& m)
|
||||
{
|
||||
trans_affine t = m;
|
||||
t.invert();
|
||||
return multiply(t);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline const trans_affine& trans_affine::premultiply_inv(const trans_affine& m)
|
||||
{
|
||||
trans_affine t = m;
|
||||
t.invert();
|
||||
return *this = t.multiply(*this);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline void trans_affine::scaling_abs(double* x, double* y) const
|
||||
{
|
||||
// Used to calculate scaling coefficients in image resampling.
|
||||
// When there is considerable shear this method gives us much
|
||||
// better estimation than just sx, sy.
|
||||
*x = sqrt(sx * sx + shx * shx);
|
||||
*y = sqrt(shy * shy + sy * sy);
|
||||
}
|
||||
|
||||
//====================================================trans_affine_rotation
|
||||
// Rotation matrix. sin() and cos() are calculated twice for the same angle.
|
||||
// There's no harm because the performance of sin()/cos() is very good on all
|
||||
// modern processors. Besides, this operation is not going to be invoked too
|
||||
// often.
|
||||
class trans_affine_rotation : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_rotation(double a) :
|
||||
trans_affine(cos(a), sin(a), -sin(a), cos(a), 0.0, 0.0)
|
||||
{}
|
||||
};
|
||||
|
||||
//====================================================trans_affine_scaling
|
||||
// Scaling matrix. x, y - scale coefficients by X and Y respectively
|
||||
class trans_affine_scaling : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_scaling(double x, double y) :
|
||||
trans_affine(x, 0.0, 0.0, y, 0.0, 0.0)
|
||||
{}
|
||||
|
||||
trans_affine_scaling(double s) :
|
||||
trans_affine(s, 0.0, 0.0, s, 0.0, 0.0)
|
||||
{}
|
||||
};
|
||||
|
||||
//================================================trans_affine_translation
|
||||
// Translation matrix
|
||||
class trans_affine_translation : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_translation(double x, double y) :
|
||||
trans_affine(1.0, 0.0, 0.0, 1.0, x, y)
|
||||
{}
|
||||
};
|
||||
|
||||
//====================================================trans_affine_skewing
|
||||
// Sckewing (shear) matrix
|
||||
class trans_affine_skewing : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_skewing(double x, double y) :
|
||||
trans_affine(1.0, tan(y), tan(x), 1.0, 0.0, 0.0)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
//===============================================trans_affine_line_segment
|
||||
// Rotate, Scale and Translate, associating 0...dist with line segment
|
||||
// x1,y1,x2,y2
|
||||
class trans_affine_line_segment : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_line_segment(double x1, double y1, double x2, double y2,
|
||||
double dist)
|
||||
{
|
||||
double dx = x2 - x1;
|
||||
double dy = y2 - y1;
|
||||
if(dist > 0.0)
|
||||
{
|
||||
multiply(trans_affine_scaling(sqrt(dx * dx + dy * dy) / dist));
|
||||
}
|
||||
multiply(trans_affine_rotation(atan2(dy, dx)));
|
||||
multiply(trans_affine_translation(x1, y1));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//============================================trans_affine_reflection_unit
|
||||
// Reflection matrix. Reflect coordinates across the line through
|
||||
// the origin containing the unit vector (ux, uy).
|
||||
// Contributed by John Horigan
|
||||
class trans_affine_reflection_unit : public trans_affine
|
||||
{
|
||||
public:
|
||||
trans_affine_reflection_unit(double ux, double uy) :
|
||||
trans_affine(2.0 * ux * ux - 1.0,
|
||||
2.0 * ux * uy,
|
||||
2.0 * ux * uy,
|
||||
2.0 * uy * uy - 1.0,
|
||||
0.0, 0.0)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
//=================================================trans_affine_reflection
|
||||
// Reflection matrix. Reflect coordinates across the line through
|
||||
// the origin at the angle a or containing the non-unit vector (x, y).
|
||||
// Contributed by John Horigan
|
||||
class trans_affine_reflection : public trans_affine_reflection_unit
|
||||
{
|
||||
public:
|
||||
trans_affine_reflection(double a) :
|
||||
trans_affine_reflection_unit(cos(a), sin(a))
|
||||
{}
|
||||
|
||||
|
||||
trans_affine_reflection(double x, double y) :
|
||||
trans_affine_reflection_unit(x / sqrt(x * x + y * y), y / sqrt(x * x + y * y))
|
||||
{}
|
||||
};
|
||||
}
|
||||
286
AVSEBOOKWriter2/Common/ap_AggPlusEnums.h
Normal file
286
AVSEBOOKWriter2/Common/ap_AggPlusEnums.h
Normal file
@ -0,0 +1,286 @@
|
||||
//
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _AGGPLUSENUMS_H
|
||||
#define _AGGPLUSENUMS_H
|
||||
|
||||
#include "ap_AggPlusTypes.h"
|
||||
|
||||
//#define __cplusplus
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
|
||||
#define PixelFormatIndexed 0x00010000 // Indexes into a palette
|
||||
#define PixelFormatGDI 0x00020000 // Is a GDI-supported format
|
||||
#define PixelFormatAlpha 0x00040000 // Has an alpha component
|
||||
#define PixelFormatPAlpha 0x00080000 // Pre-multiplied alpha
|
||||
#define PixelFormatExtended 0x00100000 // Extended color 16 bits/channel
|
||||
#define PixelFormatCanonical 0x00200000
|
||||
|
||||
#define PixelFormatUndefined 0
|
||||
#define PixelFormatDontCare 0
|
||||
|
||||
#define PixelFormat1bppIndexed (1 | ( 1 << 8) | PixelFormatIndexed | PixelFormatGDI)
|
||||
#define PixelFormat4bppIndexed (2 | ( 4 << 8) | PixelFormatIndexed | PixelFormatGDI)
|
||||
#define PixelFormat8bppIndexed (3 | ( 8 << 8) | PixelFormatIndexed | PixelFormatGDI)
|
||||
#define PixelFormat16bppGrayScale (4 | (16 << 8) | PixelFormatExtended)
|
||||
#define PixelFormat16bppRGB555 (5 | (16 << 8) | PixelFormatGDI)
|
||||
#define PixelFormat16bppRGB565 (6 | (16 << 8) | PixelFormatGDI)
|
||||
#define PixelFormat16bppARGB1555 (7 | (16 << 8) | PixelFormatAlpha | PixelFormatGDI)
|
||||
#define PixelFormat24bppRGB (8 | (24 << 8) | PixelFormatGDI)
|
||||
#define PixelFormat32bppRGB (9 | (32 << 8) | PixelFormatGDI)
|
||||
#define PixelFormat32bppARGB (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical)
|
||||
#define PixelFormat32bppPARGB (11 | (32 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatGDI)
|
||||
#define PixelFormat48bppRGB (12 | (48 << 8) | PixelFormatExtended)
|
||||
#define PixelFormat64bppARGB (13 | (64 << 8) | PixelFormatAlpha | PixelFormatCanonical | PixelFormatExtended)
|
||||
#define PixelFormat64bppPARGB (14 | (64 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatExtended)
|
||||
#define PixelFormatMax 15
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Matrix Order
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum MatrixOrder
|
||||
{
|
||||
MatrixOrderPrepend = 0,
|
||||
MatrixOrderAppend = 1
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Dash style constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum DashStyle
|
||||
{
|
||||
DashStyleSolid, // 0
|
||||
DashStyleDash, // 1
|
||||
DashStyleDot, // 2
|
||||
DashStyleDashDot, // 3
|
||||
DashStyleDashDotDot, // 4
|
||||
DashStyleCustom // 5
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Line join constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum LineJoin
|
||||
{
|
||||
LineJoinMiter = 0,
|
||||
LineJoinBevel = 1,
|
||||
LineJoinRound = 2,
|
||||
LineJoinMiterClipped = 3
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Line cap constants
|
||||
//--------------------------------------------------------------------------
|
||||
enum LineCap
|
||||
{
|
||||
LineCapFlat = 0,
|
||||
LineCapSquare = 1,
|
||||
LineCapRound = 2,
|
||||
LineCapTriangle = 3,
|
||||
|
||||
LineCapNoAnchor = 0x10, // corresponds to flat cap
|
||||
LineCapSquareAnchor = 0x11, // corresponds to square cap
|
||||
LineCapRoundAnchor = 0x12, // corresponds to round cap
|
||||
LineCapDiamondAnchor = 0x13, // corresponds to triangle cap
|
||||
LineCapArrowAnchor = 0x14, // no correspondence
|
||||
|
||||
LineCapCustom = 0xff, // custom cap
|
||||
|
||||
LineCapAnchorMask = 0xf0 // mask to check for anchor or not.
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Brush types
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum BrushType
|
||||
{
|
||||
BrushTypeSolidColor = 0,
|
||||
BrushTypeHatchFill = 1,
|
||||
BrushTypeTextureFill = 2,
|
||||
BrushTypePathGradient = 3,
|
||||
BrushTypeLinearGradient = 4
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Various wrap modes for brushes
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum WrapMode
|
||||
{
|
||||
WrapModeTile, // 0
|
||||
WrapModeTileFlipX, // 1
|
||||
WrapModeTileFlipY, // 2
|
||||
WrapModeTileFlipXY, // 3
|
||||
WrapModeClamp // 4
|
||||
};
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// FontStyle: face types and common styles
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum FontStyle
|
||||
{
|
||||
FontStyleRegular = 0,
|
||||
FontStyleBold = 1,
|
||||
FontStyleItalic = 2,
|
||||
FontStyleBoldItalic = 3,
|
||||
FontStyleUnderline = 4,
|
||||
FontStyleStrikeout = 8
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// String alignment flags
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
enum StringAlignment
|
||||
{
|
||||
// Left edge for left-to-right text,
|
||||
// right for right-to-left text,
|
||||
// and top for vertical
|
||||
StringAlignmentNear = 0,
|
||||
StringAlignmentCenter = 1,
|
||||
StringAlignmentFar = 2
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//############## Not implemented-Used
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Unit constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum Unit
|
||||
{
|
||||
UnitWorld, // 0 -- World coordinate (non-physical unit)
|
||||
UnitDisplay, // 1 -- Variable -- for PageTransform only
|
||||
UnitPixel, // 2 -- Each unit is one device pixel.
|
||||
UnitPoint, // 3 -- Each unit is a printer's point, or 1/72 inch.
|
||||
UnitInch, // 4 -- Each unit is 1 inch.
|
||||
UnitDocument, // 5 -- Each unit is 1/300 inch.
|
||||
UnitMillimeter // 6 -- Each unit is 1 millimeter.
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Text Rendering Hint
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
enum TextRenderingHint
|
||||
{
|
||||
TextRenderingHintSystemDefault = 0, // Glyph with system default rendering hint
|
||||
TextRenderingHintSingleBitPerPixelGridFit, // Glyph bitmap with hinting
|
||||
TextRenderingHintSingleBitPerPixel, // Glyph bitmap without hinting
|
||||
TextRenderingHintAntiAliasGridFit, // Glyph anti-alias bitmap with hinting
|
||||
TextRenderingHintAntiAlias, // Glyph anti-alias bitmap without hinting
|
||||
TextRenderingHintClearTypeGridFit // Glyph CT bitmap with hinting
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Quality mode constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum QualityMode
|
||||
{
|
||||
QualityModeInvalid = -1,
|
||||
QualityModeDefault = 0,
|
||||
QualityModeLow = 1, // Best performance
|
||||
QualityModeHigh = 2 // Best rendering quality
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Alpha Compositing mode constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum CompositingMode
|
||||
{
|
||||
CompositingModeSourceOver, // 0
|
||||
CompositingModeSourceCopy // 1
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Alpha Compositing quality constants
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum CompositingQuality
|
||||
{
|
||||
CompositingQualityInvalid = QualityModeInvalid,
|
||||
CompositingQualityDefault = QualityModeDefault,
|
||||
CompositingQualityHighSpeed = QualityModeLow,
|
||||
CompositingQualityHighQuality = QualityModeHigh,
|
||||
CompositingQualityGammaCorrected,
|
||||
CompositingQualityAssumeLinear
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Smoothing Mode
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
enum SmoothingMode
|
||||
{
|
||||
SmoothingModeInvalid = QualityModeInvalid,
|
||||
SmoothingModeDefault = QualityModeDefault,
|
||||
SmoothingModeHighSpeed = QualityModeLow,
|
||||
SmoothingModeHighQuality = QualityModeHigh,
|
||||
SmoothingModeNone,
|
||||
SmoothingModeAntiAlias
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Interpolation modes
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum InterpolationMode
|
||||
{
|
||||
InterpolationModeInvalid = QualityModeInvalid,
|
||||
InterpolationModeDefault = QualityModeDefault,
|
||||
InterpolationModeLowQuality = QualityModeLow,
|
||||
InterpolationModeHighQuality = QualityModeHigh,
|
||||
InterpolationModeBilinear,
|
||||
InterpolationModeBicubic,
|
||||
InterpolationModeNearestNeighbor,
|
||||
InterpolationModeHighQualityBilinear,
|
||||
InterpolationModeHighQualityBicubic
|
||||
};
|
||||
|
||||
|
||||
|
||||
enum StringFormatFlags
|
||||
{
|
||||
//not supp StringFormatFlagsDirectionRightToLeft = 0x00000001,
|
||||
//not supp StringFormatFlagsDirectionVertical = 0x00000002,
|
||||
//not supp StringFormatFlagsNoFitBlackBox = 0x00000004,
|
||||
//not supp StringFormatFlagsDisplayFormatControl = 0x00000020,
|
||||
//not supp StringFormatFlagsNoFontFallback = 0x00000400,
|
||||
//not supp StringFormatFlagsMeasureTrailingSpaces = 0x00000800,
|
||||
//not supp StringFormatFlagsNoWrap = 0x00001000,
|
||||
StringFormatFlagsLineLimit = 0x00002000
|
||||
|
||||
//not supp StringFormatFlagsNoClip = 0x00004000
|
||||
};
|
||||
|
||||
|
||||
} //namespace Aggplus
|
||||
|
||||
#endif // !defined(_AGGPLUSENUMS_H)
|
||||
173
AVSEBOOKWriter2/Common/ap_AggPlusTypes.h
Normal file
173
AVSEBOOKWriter2/Common/ap_AggPlusTypes.h
Normal file
@ -0,0 +1,173 @@
|
||||
|
||||
|
||||
#ifndef _AGGPLUSTYPES_H
|
||||
#define _AGGPLUSTYPES_H
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
|
||||
typedef float REAL;
|
||||
typedef int INT;
|
||||
typedef unsigned int *PUINT;
|
||||
typedef unsigned long ARGB;
|
||||
|
||||
typedef INT PixelFormat;
|
||||
|
||||
#define REAL_MAX FLT_MAX
|
||||
#define REAL_MIN FLT_MIN
|
||||
#define REAL_TOLERANCE (FLT_MIN * 100)
|
||||
#define REAL_EPSILON 1.192092896e-07F /* FLT_EPSILON */
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Status return values from AGG+ methods
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum Status
|
||||
{
|
||||
Ok = 0,
|
||||
GenericError = 1,
|
||||
InvalidParameter = 2,
|
||||
OutOfMemory = 3,
|
||||
ObjectBusy = 4,
|
||||
InsufficientBuffer = 5,
|
||||
NotImplemented = 6,
|
||||
Win32Error = 7,
|
||||
WrongState = 8,
|
||||
Aborted = 9,
|
||||
FileNotFound = 10,
|
||||
ValueOverflow = 11,
|
||||
AccessDenied = 12,
|
||||
UnknownImageFormat = 13,
|
||||
FontFamilyNotFound = 14,
|
||||
FontStyleNotFound = 15,
|
||||
NotTrueTypeFont = 16,
|
||||
UnsupportedGdiplusVersion = 17,
|
||||
AggplusNotInitialized = 18,
|
||||
PropertyNotFound = 19,
|
||||
PropertyNotSupported = 20
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class SizeF
|
||||
{
|
||||
public:
|
||||
SizeF() : Width(0.0f), Height(0.0f) { }
|
||||
SizeF(const SizeF& size) : Width(size.Width), Height(size.Height) { }
|
||||
SizeF(REAL width, REAL height) : Width(width), Height(height) { }
|
||||
|
||||
SizeF operator+(const SizeF& sz) const { return SizeF(Width+sz.Width, Height+sz.Height); }
|
||||
SizeF operator-(const SizeF& sz) const { return SizeF(Width-sz.Width, Height-sz.Height); }
|
||||
BOOL Equals(const SizeF& sz) const { return((Width == sz.Width) && (Height == sz.Height)); }
|
||||
BOOL Empty() const { return(Width == 0.0f && Height == 0.0f); }
|
||||
|
||||
public:
|
||||
REAL Width, Height;
|
||||
};
|
||||
|
||||
|
||||
class PointF
|
||||
{
|
||||
public:
|
||||
PointF() : X(0.0f), Y(0.0f) { }
|
||||
PointF(const PointF &point) : X(point.X), Y(point.Y) { }
|
||||
PointF(const SizeF &size) : X(size.Width), Y(size.Height) { }
|
||||
PointF(REAL x, REAL y) : X(x), Y(y) { }
|
||||
//~PointF() { }
|
||||
BOOL Equals(const PointF& point) const { return(X==point.X && Y==point.Y); }
|
||||
PointF operator+(const PointF& point) const { return PointF(X + point.X, Y + point.Y); }
|
||||
PointF operator-(const PointF& point) const { return PointF(X - point.X, Y - point.Y); }
|
||||
public:
|
||||
REAL X, Y;
|
||||
};
|
||||
|
||||
class RectF
|
||||
{
|
||||
public:
|
||||
RectF() : X(0.0f), Y(0.0f), Width(0.0f), Height(0.0f) { }
|
||||
RectF(REAL x, REAL y, REAL width, REAL height) : X(x), Y(y), Width(width), Height(height) { }
|
||||
RectF(RECT rct)
|
||||
{ X = REAL(rct.left); Y = REAL(rct.top); Width = REAL(rct.right-rct.left); Height=REAL(rct.bottom-rct.top);}
|
||||
RectF(const PointF& location, const SizeF& size) : X(location.X), Y(location.Y), Width(size.Width), Height(size.Height) { }
|
||||
|
||||
RectF* Clone() const { return new RectF(X, Y, Width, Height); }
|
||||
|
||||
void GetLocation(PointF* point) const { point->X = X; point->Y = Y; }
|
||||
void GetSize(SizeF* size) const { size->Width = Width; size->Height = Height; }
|
||||
void GetBounds(RectF* rect) const { rect->X = X; rect->Y = Y; rect->Width = Width; rect->Height = Height; }
|
||||
REAL GetLeft() const { return X; }
|
||||
REAL GetTop() const { return Y; }
|
||||
REAL GetRight() const { return X+Width; }
|
||||
REAL GetBottom() const { return Y+Height; }
|
||||
BOOL IsEmptyArea() const { return (Width <= REAL_EPSILON) || (Height <= REAL_EPSILON); }
|
||||
BOOL Equals(const RectF & rect) const
|
||||
{
|
||||
return X == rect.X && Y == rect.Y &&
|
||||
Width == rect.Width && Height == rect.Height;
|
||||
}
|
||||
BOOL Contains(REAL x, REAL y) const
|
||||
{
|
||||
return x >= X && x < X+Width &&
|
||||
y >= Y && y < Y+Height;
|
||||
}
|
||||
BOOL Contains(const PointF& pt) const { return Contains(pt.X, pt.Y); }
|
||||
BOOL Contains(const RectF& rect) const
|
||||
{
|
||||
return (X <= rect.X) && (rect.GetRight() <= GetRight()) &&
|
||||
(Y <= rect.Y) && (rect.GetBottom() <= GetBottom());
|
||||
}
|
||||
|
||||
void Inflate(REAL dx, REAL dy) { X -= dx; Y -= dy; Width += 2*dx; Height += 2*dy; }
|
||||
void Inflate(const PointF& point) { Inflate(point.X, point.Y); }
|
||||
|
||||
BOOL Intersect(const RectF& rect) { return Intersect(*this, *this, rect); }
|
||||
static BOOL Intersect(RectF& c, const RectF& a, const RectF& b)
|
||||
{
|
||||
REAL right = min(a.GetRight(), b.GetRight());
|
||||
REAL bottom = min(a.GetBottom(), b.GetBottom());
|
||||
REAL left = max(a.GetLeft(), b.GetLeft());
|
||||
REAL top = max(a.GetTop(), b.GetTop());
|
||||
|
||||
c.X = left;
|
||||
c.Y = top;
|
||||
c.Width = right - left;
|
||||
c.Height = bottom - top;
|
||||
return !c.IsEmptyArea();
|
||||
}
|
||||
|
||||
BOOL IntersectsWith(const RectF& rect) const
|
||||
{
|
||||
return (GetLeft() < rect.GetRight() &&
|
||||
GetTop() < rect.GetBottom() &&
|
||||
GetRight() > rect.GetLeft() &&
|
||||
GetBottom() > rect.GetTop());
|
||||
}
|
||||
|
||||
static BOOL Union(RectF& c, const RectF& a, const RectF& b)
|
||||
{
|
||||
REAL right = max(a.GetRight(), b.GetRight());
|
||||
REAL bottom = max(a.GetBottom(), b.GetBottom());
|
||||
REAL left = min(a.GetLeft(), b.GetLeft());
|
||||
REAL top = min(a.GetTop(), b.GetTop());
|
||||
|
||||
c.X = left;
|
||||
c.Y = top;
|
||||
c.Width = right - left;
|
||||
c.Height = bottom - top;
|
||||
return !c.IsEmptyArea();
|
||||
}
|
||||
|
||||
void Offset(const PointF& point) { Offset(point.X, point.Y); }
|
||||
void Offset(REAL dx, REAL dy) { X += dx; Y += dy; }
|
||||
|
||||
public:
|
||||
REAL X, Y, Width, Height;
|
||||
};
|
||||
|
||||
|
||||
} //namespace Aggplus
|
||||
|
||||
#endif // _AGGPLUSTYPES_H
|
||||
1624
AVSEBOOKWriter2/Common/fontmanagerbase.h
Normal file
1624
AVSEBOOKWriter2/Common/fontmanagerbase.h
Normal file
File diff suppressed because it is too large
Load Diff
1437
AVSEBOOKWriter2/Common/structures.h
Normal file
1437
AVSEBOOKWriter2/Common/structures.h
Normal file
File diff suppressed because it is too large
Load Diff
1396
AVSEBOOKWriter2/EBOOKWriter.cpp
Normal file
1396
AVSEBOOKWriter2/EBOOKWriter.cpp
Normal file
File diff suppressed because it is too large
Load Diff
596
AVSEBOOKWriter2/EBOOKWriter.h
Normal file
596
AVSEBOOKWriter2/EBOOKWriter.h
Normal file
@ -0,0 +1,596 @@
|
||||
// EBOOKWriter.h : Declaration of the CAVSEBOOKWriter
|
||||
|
||||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "resource.h" // main symbols
|
||||
|
||||
#include "MOBIFormat/MobiReader.h"
|
||||
#include "Writers/Writer_Fb2.h"
|
||||
#include "Writers/Writer_Epub.h"
|
||||
#include "Writers/Writer_Mobi.h"
|
||||
#include "Writers/Writer_Docx.h"
|
||||
|
||||
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
|
||||
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
|
||||
#endif
|
||||
|
||||
// IAVSEBOOKWriter
|
||||
[object, uuid("304A27A4-1792-4a1b-BD44-CE5F127D2895"), dual, pointer_default(unique)]
|
||||
__interface IAVSEBOOKWriter : IAVSRenderer
|
||||
{
|
||||
[id(11001)] HRESULT Initialize([in]BSTR bsXMLOptions);
|
||||
[id(11002)] HRESULT SetMetadata([in]BSTR bsXMLOptions);
|
||||
|
||||
[id(12001)] HRESULT CreateOfficeFile([in]BSTR bstrFileName, [in] LONG lFileType);
|
||||
[id(12002)] HRESULT CloseFile();
|
||||
|
||||
[id(12003), propget] HRESULT TempDirectory([out, retval]BSTR* pbstrFileName);
|
||||
[id(12003), propput] HRESULT TempDirectory([in]BSTR bstrFileName);
|
||||
|
||||
[id(12004), propget] HRESULT SrcFileType([out, retval]LONG* plSrcFileType);
|
||||
[id(12004), propput] HRESULT SrcFileType([in]LONG lSrcType);
|
||||
|
||||
[id(12500), propget] HRESULT CommandRenderer([out, retval] IUnknown** ppunkRend);
|
||||
[id(12500), propput] HRESULT CommandRenderer([in] IUnknown* punkRend);
|
||||
};
|
||||
|
||||
// CAVSEBOOKWriter
|
||||
[coclass, default(IAVSEBOOKWriter), threading(apartment), vi_progid("AVSEBOOKWriter.EBOOKWriter"), progid("AVSEBOOKWriter.EBOOKWriter.1"), version(1.0), uuid("8B8FEDFC-38D5-4d13-BDE5-549CD09A6809")]
|
||||
class ATL_NO_VTABLE CAVSEBOOKWriter :
|
||||
public IAVSEBOOKWriter, public IAVSRenderer2
|
||||
{
|
||||
private:
|
||||
NSStructures::CPen m_oPen; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> AVSGraphics)
|
||||
NSStructures::CBrush m_oBrush;
|
||||
NSStructures::CFont m_oFont;
|
||||
NSStructures::CFormat m_oFormat;
|
||||
NSStructures::CShadow m_oShadow;
|
||||
NSStructures::CEdgeText m_oEdge;
|
||||
|
||||
AVSGraphics::IAVSGraphicSimpleComverter* m_pSimpleGraphicsConverter; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
AVSGraphics::IAVSFontManager* m_pFontManager; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
NSCommon::CMatrix m_oBaseTransform; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
NSCommon::CMatrix m_oTransform; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
NSCommon::CMatrix m_oFullTransform; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (m_oBaseTransform * m_oTransform)
|
||||
|
||||
double m_dTransformAngle;
|
||||
|
||||
LONG m_lCurrentCommandType; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
bool m_bIsMetafileDrawing;
|
||||
|
||||
double m_dDpiX;
|
||||
double m_dDpiY;
|
||||
|
||||
LONG m_lClipMode;
|
||||
NSStructures::CFont m_oInstalledFont;
|
||||
|
||||
double m_dWidth;
|
||||
double m_dHeight;
|
||||
bool m_bPageAdded;
|
||||
|
||||
NSEBook::CWriter m_oWriter;
|
||||
|
||||
CRITICAL_SECTION m_oCS;
|
||||
|
||||
CString m_strDstFilePath;
|
||||
CString m_strTempDirectory;
|
||||
|
||||
LONG m_lSrcType;
|
||||
LONG m_lDstType;
|
||||
|
||||
NSEBook::CRenderers* m_pRenderers;
|
||||
|
||||
DWORD m_lCommandFlags;
|
||||
|
||||
AVSGraphics::IAVSDocumentRenderer * m_piCommandsRenderer;
|
||||
|
||||
public:
|
||||
CAVSEBOOKWriter()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
|
||||
/*
|
||||
NSMobi::CMobiReader oReaderMobi;
|
||||
oReaderMobi.OpenFile(_T("C:\\PPTMemory\\Guide.mobi"));
|
||||
oReaderMobi.CloseFile();
|
||||
*/
|
||||
|
||||
/*
|
||||
m_oWriter.m_oFormat.LoadFromFile(_T("C:\\PPTMemory\\test_format_input.xml"));
|
||||
m_oWriter.m_oFormat.SaveToFile(_T("C:\\PPTMemory\\test_format_output.xml"));
|
||||
m_lDstType = 1;
|
||||
CloseFile();
|
||||
*/
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
DECLARE_PROTECT_FINAL_CONSTRUCT()
|
||||
|
||||
HRESULT FinalConstruct()
|
||||
{
|
||||
m_strDstFilePath = _T("");
|
||||
m_strTempDirectory = _T("");
|
||||
|
||||
InitializeCriticalSection(&m_oCS);
|
||||
|
||||
m_dDpiX = 96.0;
|
||||
m_dDpiY = 96.0;
|
||||
|
||||
m_lClipMode = c_nClipRegionTypeWinding;
|
||||
|
||||
m_lCommandFlags = 0;
|
||||
|
||||
m_pSimpleGraphicsConverter = NULL;
|
||||
CoCreateInstance(AVSGraphics::CLSID_CAVSGraphicSimpleComverter, NULL, CLSCTX_ALL, AVSGraphics::IID_IAVSGraphicSimpleComverter, (void**)&m_pSimpleGraphicsConverter);
|
||||
|
||||
IUnknown* punkRenderer = NULL;
|
||||
this->QueryInterface(IID_IUnknown, (void**)&punkRenderer);
|
||||
|
||||
m_pSimpleGraphicsConverter->put_Renderer(punkRenderer);
|
||||
RELEASEINTERFACE(punkRenderer);
|
||||
|
||||
m_dTransformAngle = 0.0;
|
||||
m_bIsMetafileDrawing = false;
|
||||
m_pFontManager = NULL;
|
||||
|
||||
m_pRenderers = NULL;
|
||||
m_piCommandsRenderer = NULL;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void FinalRelease()
|
||||
{
|
||||
CloseFile();
|
||||
|
||||
RELEASEINTERFACE(m_piCommandsRenderer);
|
||||
DeleteCriticalSection(&m_oCS);
|
||||
}
|
||||
|
||||
public:
|
||||
// IAVSRenderer Methods
|
||||
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-----------------------------------------------------------------------------
|
||||
STDMETHOD(get_Type)(LONG* lType);
|
||||
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --------------------------------------------------
|
||||
STDMETHOD(NewPage)();
|
||||
STDMETHOD(get_Height)(double* dHeight);
|
||||
STDMETHOD(put_Height)(double dHeight);
|
||||
STDMETHOD(get_Width)(double* dWidth);
|
||||
STDMETHOD(put_Width)(double dWidth);
|
||||
STDMETHOD(get_DpiX)(double* dDpiX);
|
||||
STDMETHOD(get_DpiY)(double* dDpiY);
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ----------------------------------------------
|
||||
STDMETHOD(SetPen)(BSTR bsXML);
|
||||
|
||||
STDMETHOD(get_PenColor)(LONG* lColor);
|
||||
STDMETHOD(put_PenColor)(LONG lColor);
|
||||
STDMETHOD(get_PenAlpha)(LONG* lAlpha);
|
||||
STDMETHOD(put_PenAlpha)(LONG lAlpha);
|
||||
STDMETHOD(get_PenSize)(double* dSize);
|
||||
STDMETHOD(put_PenSize)(double dSize);
|
||||
STDMETHOD(get_PenDashStyle)(BYTE* val);
|
||||
STDMETHOD(put_PenDashStyle)(BYTE val);
|
||||
STDMETHOD(get_PenLineStartCap)(BYTE* val);
|
||||
STDMETHOD(put_PenLineStartCap)(BYTE val);
|
||||
STDMETHOD(get_PenLineEndCap)(BYTE* val);
|
||||
STDMETHOD(put_PenLineEndCap)(BYTE val);
|
||||
STDMETHOD(get_PenLineJoin)(BYTE* val);
|
||||
STDMETHOD(put_PenLineJoin)(BYTE val);
|
||||
STDMETHOD(get_PenDashOffset)(double* val);
|
||||
STDMETHOD(put_PenDashOffset)(double val);
|
||||
STDMETHOD(get_PenAlign)(LONG* val);
|
||||
STDMETHOD(put_PenAlign)(LONG val);
|
||||
STDMETHOD(get_PenMiterLimit)(double* val);
|
||||
STDMETHOD(put_PenMiterLimit)(double val);
|
||||
STDMETHOD(PenDashPattern)(SAFEARRAY* pPattern);
|
||||
|
||||
STDMETHOD(SetBrush)(BSTR bsXML);
|
||||
|
||||
STDMETHOD(get_BrushType)(LONG* lType);
|
||||
STDMETHOD(put_BrushType)(LONG lType);
|
||||
STDMETHOD(get_BrushColor1)(LONG* lColor);
|
||||
STDMETHOD(put_BrushColor1)(LONG lColor);
|
||||
STDMETHOD(get_BrushAlpha1)(LONG* lAlpha);
|
||||
STDMETHOD(put_BrushAlpha1)(LONG lAlpha);
|
||||
STDMETHOD(get_BrushColor2)(LONG* lColor);
|
||||
STDMETHOD(put_BrushColor2)(LONG lColor);
|
||||
STDMETHOD(get_BrushAlpha2)(LONG* lAlpha);
|
||||
STDMETHOD(put_BrushAlpha2)(LONG lAlpha);
|
||||
STDMETHOD(get_BrushTexturePath)(BSTR* bsPath);
|
||||
STDMETHOD(put_BrushTexturePath)(BSTR bsPath);
|
||||
STDMETHOD(get_BrushTextureMode)(LONG* lMode);
|
||||
STDMETHOD(put_BrushTextureMode)(LONG lMode);
|
||||
STDMETHOD(get_BrushTextureAlpha)(LONG* lTxAlpha);
|
||||
STDMETHOD(put_BrushTextureAlpha)(LONG lTxAlpha);
|
||||
STDMETHOD(get_BrushLinearAngle)(double* dAngle);
|
||||
STDMETHOD(put_BrushLinearAngle)(double dAngle);
|
||||
STDMETHOD(BrushRect)(BOOL val, double left, double top, double width, double height);
|
||||
|
||||
STDMETHOD(SetFont)(BSTR bsXML);
|
||||
|
||||
STDMETHOD(get_FontName)(BSTR* bsName);
|
||||
STDMETHOD(put_FontName)(BSTR bsName);
|
||||
STDMETHOD(get_FontPath)(BSTR* bsName);
|
||||
STDMETHOD(put_FontPath)(BSTR bsName);
|
||||
STDMETHOD(get_FontSize)(double* dSize);
|
||||
STDMETHOD(put_FontSize)(double dSize);
|
||||
STDMETHOD(get_FontStyle)(LONG* lStyle);
|
||||
STDMETHOD(put_FontStyle)(LONG lStyle);
|
||||
STDMETHOD(get_FontStringGID)(BOOL* bGID);
|
||||
STDMETHOD(put_FontStringGID)(BOOL bGID);
|
||||
STDMETHOD(get_FontCharSpace)(double* dSpace);
|
||||
STDMETHOD(put_FontCharSpace)(double dSpace);
|
||||
|
||||
STDMETHOD(SetShadow)(BSTR bsXML);
|
||||
|
||||
STDMETHOD(get_ShadowDistanceX)(double* val);
|
||||
STDMETHOD(put_ShadowDistanceX)(double val);
|
||||
STDMETHOD(get_ShadowDistanceY)(double* val);
|
||||
STDMETHOD(put_ShadowDistanceY)(double val);
|
||||
STDMETHOD(get_ShadowBlurSize)(double* val);
|
||||
STDMETHOD(put_ShadowBlurSize)(double val);
|
||||
STDMETHOD(get_ShadowColor)(LONG* val);
|
||||
STDMETHOD(put_ShadowColor)(LONG val);
|
||||
STDMETHOD(get_ShadowAlpha)(LONG* val);
|
||||
STDMETHOD(put_ShadowAlpha)(LONG val);
|
||||
STDMETHOD(get_ShadowVisible)(BOOL* val);
|
||||
STDMETHOD(put_ShadowVisible)(BOOL val);
|
||||
|
||||
STDMETHOD(SetEdgeText)(BSTR bsXML);
|
||||
|
||||
STDMETHOD(get_EdgeVisible)(LONG* val);
|
||||
STDMETHOD(put_EdgeVisible)(LONG val);
|
||||
STDMETHOD(get_EdgeColor)(LONG* val);
|
||||
STDMETHOD(put_EdgeColor)(LONG val);
|
||||
STDMETHOD(get_EdgeAlpha)(LONG* val);
|
||||
STDMETHOD(put_EdgeAlpha)(LONG val);
|
||||
STDMETHOD(get_EdgeDist)(double* val);
|
||||
STDMETHOD(put_EdgeDist)(double val);
|
||||
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --------------------------------------------------------
|
||||
STDMETHOD(CommandDrawText)(BSTR bsText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset);
|
||||
STDMETHOD(CommandDrawTextEx)(BSTR bsUnicodeText, BSTR bsGidText, BSTR bsSourceCodeText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset, DWORD lFlags);
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ---------------------------------------------------------------
|
||||
STDMETHOD(BeginCommand)(DWORD lType);
|
||||
STDMETHOD(EndCommand)(DWORD lType);
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> Graphics Path -----------------------------------------------
|
||||
STDMETHOD(PathCommandMoveTo)(double fX, double fY);
|
||||
STDMETHOD(PathCommandLineTo)(double fX, double fY);
|
||||
STDMETHOD(PathCommandLinesTo)(SAFEARRAY* pPoints);
|
||||
STDMETHOD(PathCommandCurveTo)(double fX1, double fY1, double fX2, double fY2, double fX3, double fY3);
|
||||
STDMETHOD(PathCommandCurvesTo)(SAFEARRAY* pPoints);
|
||||
STDMETHOD(PathCommandArcTo)(double fX, double fY, double fWidth, double fHeight, double fStartAngle, double fSweepAngle);
|
||||
STDMETHOD(PathCommandClose)();
|
||||
STDMETHOD(PathCommandEnd)();
|
||||
STDMETHOD(DrawPath)(long nType);
|
||||
STDMETHOD(PathCommandStart)();
|
||||
STDMETHOD(PathCommandGetCurrentPoint)(double* fX, double* fY);
|
||||
|
||||
STDMETHOD(PathCommandText)(BSTR bsText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset);
|
||||
STDMETHOD(PathCommandTextEx)(BSTR bsUnicodeText, BSTR bsGidText, BSTR bsSourceCodeText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset, DWORD lFlags);
|
||||
|
||||
STDMETHOD(GetCommandParams)(double* dAngle, double* dLeft, double* dTop, double* dWidth, double* dHeight, DWORD* lFlags);
|
||||
STDMETHOD(SetCommandParams)(double dAngle, double dLeft, double dTop, double dWidth, double dHeight, DWORD lFlags);
|
||||
//-------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --------------------------------------------------
|
||||
STDMETHOD(DrawImage)(IUnknown* pInterface, double fX, double fY, double fWidth, double fHeight);
|
||||
STDMETHOD(DrawImageFromFile)(BSTR bstrVal, double fX, double fY, double fWidth, double fHeight);
|
||||
//------------------------------------------------------------------------------------------
|
||||
STDMETHOD(SetAdditionalParam)(BSTR ParamName, VARIANT ParamValue);
|
||||
STDMETHOD(GetAdditionalParam)(BSTR ParamName, VARIANT* ParamValue);
|
||||
|
||||
STDMETHOD(SetTransform)(double dA, double dB, double dC, double dD, double dE, double dF);
|
||||
STDMETHOD(GetTransform)(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF);
|
||||
STDMETHOD(ResetTransform)(void);
|
||||
STDMETHOD(get_ClipMode)(LONG* plMode);
|
||||
STDMETHOD(put_ClipMode)(LONG lMode);
|
||||
|
||||
// AVSRenderer2
|
||||
STDMETHOD(CommandLong)(LONG lCommand);
|
||||
STDMETHOD(CommandDouble)(double dCommand);
|
||||
STDMETHOD(CommandString)(BSTR bsCommand);
|
||||
STDMETHOD(CommandVariant)(VARIANT vCommand);
|
||||
|
||||
STDMETHOD(CommandLong2)(LONG lType, LONG lCommand);
|
||||
STDMETHOD(CommandDouble2)(LONG lType, double dCommand);
|
||||
STDMETHOD(CommandString2)(LONG lType, BSTR bsCommand);
|
||||
STDMETHOD(CommandVariant2)(LONG lType, VARIANT vCommand);
|
||||
|
||||
public:
|
||||
//IAVSDocxRenderer Methods
|
||||
STDMETHOD(Initialize)(BSTR bsXMLOptions);
|
||||
STDMETHOD(SetMetadata)(BSTR bsXMLOptions);
|
||||
STDMETHOD(CreateOfficeFile)(BSTR bsFileName, LONG lFileType);
|
||||
STDMETHOD(CloseFile)();
|
||||
|
||||
STDMETHOD(get_CommandRenderer)(IUnknown** ppunkRend)
|
||||
{
|
||||
if(NULL == ppunkRend)
|
||||
return S_FALSE;
|
||||
(*ppunkRend) = NULL;
|
||||
if(NULL == m_piCommandsRenderer)
|
||||
return S_OK;
|
||||
return m_piCommandsRenderer->QueryInterface(__uuidof(AVSGraphics::IAVSDocumentRenderer), (void**)&ppunkRend);
|
||||
}
|
||||
STDMETHOD(put_CommandRenderer)(IUnknown* ppunkRend)
|
||||
{
|
||||
RELEASEINTERFACE(m_piCommandsRenderer);
|
||||
if(NULL != ppunkRend)
|
||||
ppunkRend->QueryInterface(__uuidof( AVSGraphics::IAVSDocumentRenderer), (void**)&m_piCommandsRenderer);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void BaseInitialize(BSTR bsXMLOptions)
|
||||
{
|
||||
XmlUtils::CXmlNode oNode;
|
||||
if (oNode.FromXmlString((CString)bsXMLOptions))
|
||||
{
|
||||
XmlUtils::CXmlNode oNodeEbook;
|
||||
if (oNode.GetNode(_T("EbookOptions"), oNodeEbook))
|
||||
{
|
||||
m_oWriter.m_bIsSaveCover = (1 == oNodeEbook.ReadValueInt(_T("SaveCover"), 0));
|
||||
m_oWriter.m_bIsEmbeddedFonts = (1 == oNodeEbook.ReadValueInt(_T("FontEmbed"), 0));
|
||||
|
||||
m_oWriter.m_bIsSaveCover = !m_oWriter.m_bIsSaveCover;
|
||||
m_oWriter.m_bIsEmbeddedFonts = !m_oWriter.m_bIsEmbeddedFonts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHOD(put_TempDirectory)(BSTR bsFileName)
|
||||
{
|
||||
m_strTempDirectory = (CString)bsFileName;
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(get_TempDirectory)(BSTR* pbsFileName)
|
||||
{
|
||||
if (NULL == pbsFileName)
|
||||
return S_FALSE;
|
||||
|
||||
*pbsFileName = m_strTempDirectory.AllocSysString();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(put_SrcFileType)(LONG lType)
|
||||
{
|
||||
m_lSrcType = lType;
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(get_SrcFileType)(LONG* plType)
|
||||
{
|
||||
if (NULL == plType)
|
||||
return S_FALSE;
|
||||
|
||||
*plType = m_lSrcType;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
AVSINLINE void SendBeginCommandsToFlags()
|
||||
{
|
||||
if (c_nHeader == m_lCurrentCommandType)
|
||||
m_lCommandFlags += 100;
|
||||
if (c_nTextGraphicType == m_lCurrentCommandType)
|
||||
m_lCommandFlags += 1000;
|
||||
if (c_nTable == m_lCurrentCommandType)
|
||||
m_lCommandFlags += 10000;
|
||||
if (c_nFootnote == m_lCurrentCommandType)
|
||||
m_lCommandFlags += 100000;
|
||||
}
|
||||
AVSINLINE void SendEndCommandsToFlags(LONG lType)
|
||||
{
|
||||
if (c_nHeader == lType)
|
||||
m_lCommandFlags -= 100;
|
||||
if (c_nTextGraphicType == lType)
|
||||
m_lCommandFlags -= 1000;
|
||||
if (c_nTable == lType)
|
||||
m_lCommandFlags -= 10000;
|
||||
if (c_nFootnote == lType)
|
||||
m_lCommandFlags -= 100000;
|
||||
}
|
||||
AVSINLINE bool CheckNeedCommands()
|
||||
{
|
||||
//return true;
|
||||
return (0 == m_lCommandFlags) ? true : false;
|
||||
}
|
||||
|
||||
private:
|
||||
AVSINLINE void ApplyTransform(double d1, double d2, double d3, double d4, double d5, double d6)
|
||||
{
|
||||
m_oTransform.SetElements(d1, d2, d3, d4, d5, d6);
|
||||
m_dTransformAngle = m_oTransform.z_Rotation();
|
||||
}
|
||||
|
||||
void ApplyTransform2(double dAngle, double dLeft, double dTop, double dWidth, double dHeight, DWORD lFlags)
|
||||
{
|
||||
if ((dWidth <= 1) || (dHeight <= 1))
|
||||
lFlags = 0;
|
||||
|
||||
BOOL bFlipX = (0 != (c_nParamFlipX & lFlags));
|
||||
BOOL bFlipY = (0 != (c_nParamFlipY & lFlags));
|
||||
|
||||
double m11 = bFlipX ? -1.0 : 1.0;
|
||||
double m22 = bFlipY ? -1.0 : 1.0;
|
||||
|
||||
NSCommon::CMatrix oMatrix(1, 0, 0, 1, 0, 0);
|
||||
|
||||
if ((0 != dAngle) || (0 != lFlags))
|
||||
{
|
||||
double dCentreX = (dLeft + dWidth / 2.0);
|
||||
double dCentreY = (dTop + dHeight / 2.0);
|
||||
|
||||
oMatrix.Translate(-dCentreX, -dCentreY , Aggplus::MatrixOrderAppend);
|
||||
|
||||
oMatrix.Rotate(dAngle , Aggplus::MatrixOrderAppend);
|
||||
oMatrix.Scale(m11, m22 , Aggplus::MatrixOrderAppend);
|
||||
|
||||
oMatrix.Translate(dCentreX, dCentreY , Aggplus::MatrixOrderAppend);
|
||||
}
|
||||
|
||||
m_oTransform = oMatrix;
|
||||
m_dTransformAngle = m_oTransform.z_Rotation();
|
||||
}
|
||||
|
||||
void _SetFont()
|
||||
{
|
||||
if (NULL == m_pFontManager)
|
||||
{
|
||||
CoCreateInstance(__uuidof(AVSGraphics::CAVSFontManager), NULL, CLSCTX_ALL, __uuidof(AVSGraphics::IAVSFontManager), (void**)&m_pFontManager);
|
||||
m_pFontManager->Initialize(L"");
|
||||
}
|
||||
|
||||
double dPix = m_oFont.CharSpace * m_dDpiX / 25.4;
|
||||
|
||||
if (m_oInstalledFont.IsEqual(&m_oFont))
|
||||
{
|
||||
if (1 < m_dWidth)
|
||||
{
|
||||
m_pFontManager->SetCharSpacing(dPix);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_pFontManager->SetStringGID(m_oFont.StringGID);
|
||||
if (1 < m_dWidth)
|
||||
{
|
||||
m_pFontManager->SetCharSpacing(dPix);
|
||||
}
|
||||
|
||||
if (_T("") == m_oFont.Path)
|
||||
{
|
||||
BSTR bsName = m_oFont.Name.AllocSysString();
|
||||
m_pFontManager->LoadFontByName(bsName, (float)m_oFont.Size, m_oFont.GetStyle(), m_dDpiX, m_dDpiY);
|
||||
SysFreeString(bsName);
|
||||
}
|
||||
else
|
||||
{
|
||||
BSTR bsName = m_oFont.Path.AllocSysString();
|
||||
m_pFontManager->LoadFontFromFile(bsName, (float)m_oFont.Size, m_dDpiX, m_dDpiY, 0);
|
||||
SysFreeString(bsName);
|
||||
}
|
||||
|
||||
m_oInstalledFont = m_oFont;
|
||||
}
|
||||
|
||||
AVSINLINE void MoveTo(double& x, double& y)
|
||||
{
|
||||
m_oWriter.MoveTo(x, y);
|
||||
}
|
||||
AVSINLINE void LineTo(double& x, double& y)
|
||||
{
|
||||
m_oWriter.LineTo(x, y);
|
||||
}
|
||||
AVSINLINE void CurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
|
||||
{
|
||||
m_oWriter.CurveTo(x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
AVSINLINE void Close()
|
||||
{
|
||||
m_oWriter.Close();
|
||||
}
|
||||
|
||||
AVSINLINE void PathStart()
|
||||
{
|
||||
m_oWriter.BeginPath();
|
||||
}
|
||||
AVSINLINE void PathEnd()
|
||||
{
|
||||
m_oWriter.EndPath();
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
bool SaveCover()
|
||||
{
|
||||
if (NULL != m_piCommandsRenderer)
|
||||
{
|
||||
long nPageCount = 0;
|
||||
m_piCommandsRenderer->get_PageCount(&nPageCount);
|
||||
if (nPageCount > 0)
|
||||
{
|
||||
double dWidthMM = 0;
|
||||
double dHeightMM = 0;
|
||||
m_piCommandsRenderer->GetPageSize( 0, &dWidthMM, &dHeightMM );
|
||||
//
|
||||
LONG nHeight = 0;
|
||||
LONG nWidth = 0;
|
||||
if( 0 != dHeightMM )
|
||||
{
|
||||
nHeight = 1186;
|
||||
nWidth = nHeight * dWidthMM / dHeightMM;
|
||||
}
|
||||
MediaCore::IAVSUncompressedVideoFrame* piImage = NULL;
|
||||
AVSGraphics::IAVSGraphicsRenderer* piGraphicsRenderer = NULL;
|
||||
UpdateGdiPlusRenderer( dWidthMM, dHeightMM, &piImage, &piGraphicsRenderer );
|
||||
if( NULL != piGraphicsRenderer )
|
||||
{
|
||||
piGraphicsRenderer->NewPage();
|
||||
m_piCommandsRenderer->DrawPage( 0, piGraphicsRenderer );
|
||||
|
||||
IUnknown* punkFrame = NULL;
|
||||
piImage->QueryInterface(IID_IUnknown, (void**)&punkFrame);
|
||||
this->DrawImage(punkFrame, 0, 0, dWidthMM, dHeightMM);
|
||||
RELEASEINTERFACE(punkFrame);
|
||||
}
|
||||
|
||||
RELEASEINTERFACE(piGraphicsRenderer);
|
||||
RELEASEINTERFACE(piImage);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UpdateGdiPlusRenderer(double dWidthMm, double dHeightMm, MediaCore::IAVSUncompressedVideoFrame** piImage, AVSGraphics::IAVSGraphicsRenderer** piRend)
|
||||
{
|
||||
(*piImage) = NULL;
|
||||
(*piRend) = NULL;
|
||||
CoCreateInstance(__uuidof( MediaCore::CAVSUncompressedVideoFrame), NULL ,CLSCTX_INPROC_SERVER, __uuidof(MediaCore::IAVSUncompressedVideoFrame), (void **)piImage);
|
||||
AVSGraphics::IAVSFontManagerPtr piFontManager;
|
||||
piFontManager.CreateInstance( __uuidof(AVSGraphics::CAVSFontManager) );
|
||||
piFontManager->Initialize( L"" );
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dpi <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int nLOGPIXELSX = 96;
|
||||
int nLOGPIXELSY = 96;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
long nWidthPix = (long)(nLOGPIXELSX * dWidthMm / (25.4));
|
||||
long nHeightPix = (long)(nLOGPIXELSY * dHeightMm / (25.4));
|
||||
|
||||
if (nHeightPix > c_nMaxImageSize)
|
||||
{
|
||||
nWidthPix = (LONG)((double)nWidthPix * c_nMaxImageSize / nHeightPix);
|
||||
nHeightPix = c_nMaxImageSize;
|
||||
}
|
||||
|
||||
(*piImage)->put_Width(nWidthPix);
|
||||
(*piImage)->put_Height(nHeightPix);
|
||||
(*piImage)->put_Stride(0, nWidthPix * 4);
|
||||
|
||||
(*piImage)->put_AspectRatioX(nWidthPix);
|
||||
(*piImage)->put_AspectRatioY(nHeightPix);
|
||||
|
||||
(*piImage)->put_DataSize(4 * nWidthPix * nHeightPix);
|
||||
|
||||
(*piImage)->put_ColorSpace(64 + (1 << 31));
|
||||
(*piImage)->AllocateBuffer(-1);
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
(*piImage)->get_Buffer(&pBuffer);
|
||||
memset(pBuffer, 255, 4 * nWidthPix * nHeightPix);
|
||||
|
||||
CoCreateInstance(__uuidof( AVSGraphics::CAVSGraphicsRenderer), NULL ,CLSCTX_INPROC_SERVER, __uuidof(AVSGraphics::IAVSGraphicsRenderer), (void **)piRend);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FontManager
|
||||
VARIANT vtVariant;
|
||||
vtVariant.vt = VT_UNKNOWN;
|
||||
vtVariant.punkVal = piFontManager;
|
||||
(*piRend)->SetAdditionalParam( L"FontManager", vtVariant );
|
||||
|
||||
(*piRend)->put_Width(dWidthMm);
|
||||
(*piRend)->put_Height(dHeightMm);
|
||||
(*piRend)->CreateFromMediaData(*piImage, 0, 0, nWidthPix, nHeightPix );
|
||||
}
|
||||
};
|
||||
|
||||
476
AVSEBOOKWriter2/Logic/EbookPage.h
Normal file
476
AVSEBOOKWriter2/Logic/EbookPage.h
Normal file
@ -0,0 +1,476 @@
|
||||
#pragma once
|
||||
#include "../Common/FontManager.h"
|
||||
#include "Text.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class IEbookItem
|
||||
{
|
||||
public:
|
||||
enum EEBookItemType
|
||||
{
|
||||
ebitParagraph = 0,
|
||||
ebitTable = 1,
|
||||
ebitGraphic = 2,
|
||||
ebitNumbering = 3
|
||||
};
|
||||
|
||||
public:
|
||||
EEBookItemType m_eType;
|
||||
CDoubleRect m_rcBounds;
|
||||
bool m_bIsPageBreakAfter;
|
||||
|
||||
public:
|
||||
virtual void ReadFromXml(XmlUtils::CXmlNode& oNode) = 0;
|
||||
virtual CString SaveToXml() = 0;
|
||||
};
|
||||
|
||||
class CEbookTable : public IEbookItem
|
||||
{
|
||||
public:
|
||||
CString m_strTableXml;
|
||||
|
||||
public:
|
||||
CEbookTable()
|
||||
{
|
||||
m_eType = ebitTable;
|
||||
m_strTableXml = _T("");
|
||||
m_bIsPageBreakAfter = false;
|
||||
}
|
||||
~CEbookTable()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void ReadFromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
m_strTableXml = oNode.GetXml();
|
||||
}
|
||||
virtual CString SaveToXml()
|
||||
{
|
||||
return m_strTableXml;
|
||||
}
|
||||
};
|
||||
|
||||
class CEbookGraphicObject : public IEbookItem
|
||||
{
|
||||
public:
|
||||
NSCommon::CImageInfo m_oInfo;
|
||||
LONG m_lWrapMode;
|
||||
|
||||
public:
|
||||
CEbookGraphicObject()
|
||||
{
|
||||
m_eType = ebitGraphic;
|
||||
m_lWrapMode = 0;
|
||||
m_bIsPageBreakAfter = false;
|
||||
}
|
||||
~CEbookGraphicObject()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void ReadFromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
m_lWrapMode = oNode.ReadAttributeInt(_T("wrap"));
|
||||
m_rcBounds.left = 0;
|
||||
m_rcBounds.top = 0;
|
||||
m_rcBounds.right = oNode.ReadAttributeDouble(_T("width"));
|
||||
m_rcBounds.bottom = oNode.ReadAttributeDouble(_T("height"));
|
||||
m_oInfo.m_lID = oNode.ReadAttributeInt(_T("id"));
|
||||
m_oInfo.m_eType = (_T("jpg") == oNode.GetAttribute(_T("type"))) ? NSCommon::itJPG : NSCommon::itPNG;
|
||||
}
|
||||
virtual CString SaveToXml()
|
||||
{
|
||||
CString strRet = _T("");
|
||||
strRet.Format(_T("<graphic wrap=\"%d\" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" id=\"%d\" type=\"%s\"/>"),
|
||||
m_lWrapMode, 0, 0, m_rcBounds.GetWidth(), m_rcBounds.GetHeight(), m_oInfo.m_lID,
|
||||
(NSCommon::itJPG == m_oInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
return strRet;
|
||||
}
|
||||
};
|
||||
|
||||
class CEbookParagraph : public IEbookItem
|
||||
{
|
||||
public:
|
||||
class CSpan
|
||||
{
|
||||
public:
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> - <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD>. <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>!!!
|
||||
CImageInfo m_oImageInfo;
|
||||
double m_dImageWidth;
|
||||
double m_dImageHeight;
|
||||
|
||||
double m_dX;
|
||||
double m_dWidthSpan;
|
||||
|
||||
double m_dBaselineOffset;
|
||||
|
||||
NSStructures::CFont m_oFont;
|
||||
NSStructures::CBrush m_oBrush;
|
||||
CTextItem m_oText;
|
||||
|
||||
public:
|
||||
CSpan() : m_oImageInfo(), m_oFont(), m_oBrush(), m_oText(10)
|
||||
{
|
||||
m_dImageWidth = 0;
|
||||
m_dImageHeight = 0;
|
||||
|
||||
m_dX = 0;
|
||||
m_dWidthSpan = 0;
|
||||
|
||||
m_dBaselineOffset = 0;
|
||||
}
|
||||
~CSpan()
|
||||
{
|
||||
}
|
||||
CSpan(const CSpan& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CSpan& operator=(const CSpan& oSrc)
|
||||
{
|
||||
m_oImageInfo = oSrc.m_oImageInfo;
|
||||
m_dImageWidth = oSrc.m_dImageWidth;
|
||||
m_dImageHeight = oSrc.m_dImageHeight;
|
||||
|
||||
m_dX = oSrc.m_dX;
|
||||
m_dWidthSpan = oSrc.m_dWidthSpan;
|
||||
m_dBaselineOffset = oSrc.m_dBaselineOffset;
|
||||
|
||||
m_oFont = oSrc.m_oFont;
|
||||
m_oBrush = oSrc.m_oBrush;
|
||||
m_oText = oSrc.m_oText;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CString ToXml()
|
||||
{
|
||||
if (-1 != m_oImageInfo.m_lID)
|
||||
{
|
||||
CString strRet = _T("");
|
||||
strRet.Format(_T("<image id=\"%d\" type=\"%d\"/>"), m_oImageInfo.m_lID, (int)m_oImageInfo.m_eType);
|
||||
return strRet;
|
||||
}
|
||||
CString strRet = _T("");
|
||||
strRet.Format(_T("<span baselineoffset=\"%d\">"), (LONG)m_dBaselineOffset);
|
||||
strRet += m_oFont.ToXmlString();
|
||||
strRet += m_oBrush.ToXmlString();
|
||||
strRet += m_oText.GetCString();
|
||||
strRet += _T("</span>");
|
||||
return strRet;
|
||||
}
|
||||
void FromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
if (_T("image") == oNode.GetName())
|
||||
{
|
||||
m_oImageInfo.m_lID = oNode.ReadAttributeInt(_T("id"));
|
||||
m_oImageInfo.m_eType = (NSCommon::ImageType)oNode.ReadAttributeInt(_T("type"));
|
||||
return;
|
||||
}
|
||||
|
||||
m_dBaselineOffset = oNode.ReadAttributeDouble(_T("baselineoffset"));
|
||||
XmlUtils::CXmlNodes oNodes;
|
||||
if (oNode.GetChilds(oNodes))
|
||||
{
|
||||
int nCount = oNodes.GetCount();
|
||||
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oNodeS;
|
||||
oNodes.GetAt(i, oNodeS);
|
||||
|
||||
CString sName = oNodeS.GetName();
|
||||
|
||||
if (_T("#text") == sName)
|
||||
{
|
||||
m_oText += (CString)oNodeS.GetXml();
|
||||
}
|
||||
else if (_T("font") == sName)
|
||||
{
|
||||
m_oFont.FromXmlNode(oNodeS);
|
||||
}
|
||||
else if (_T("brush") == sName)
|
||||
{
|
||||
m_oBrush.FromXmlNode(oNodeS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
class CLine
|
||||
{
|
||||
public:
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> - <20><> <20><><EFBFBD> Image <20><><EFBFBD><EFBFBD><EFBFBD>. <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
CImageInfo m_oImageInfo;
|
||||
CAtlList<CSpan> m_listSpans;
|
||||
|
||||
double m_dTop;
|
||||
double m_dBaselinePos;
|
||||
|
||||
public:
|
||||
CLine() : m_listSpans(), m_oImageInfo()
|
||||
{
|
||||
m_dTop = -1;
|
||||
m_dBaselinePos = -1;
|
||||
}
|
||||
~CLine()
|
||||
{
|
||||
}
|
||||
CLine(const CLine& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CLine& operator=(const CLine& oSrc)
|
||||
{
|
||||
m_dTop = oSrc.m_dTop;
|
||||
m_dBaselinePos = oSrc.m_dBaselinePos;
|
||||
|
||||
m_oImageInfo = oSrc.m_oImageInfo;
|
||||
m_listSpans.RemoveAll();
|
||||
|
||||
POSITION pos = oSrc.m_listSpans.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CSpan oSpan = oSrc.m_listSpans.GetNext(pos);
|
||||
m_listSpans.AddTail(oSpan);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
AVSINLINE bool CheckTitle()
|
||||
{
|
||||
if (-1 != m_oImageInfo.m_lID)
|
||||
return false;
|
||||
|
||||
POSITION pos = m_listSpans.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CSpan& oSpan = m_listSpans.GetNext(pos);
|
||||
if (oSpan.m_dBaselineOffset != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
LONG m_lTextAlign;
|
||||
LONG m_lStyle;
|
||||
LONG m_lNumberingLevel;
|
||||
|
||||
bool m_bIsComplete;
|
||||
CAtlList<CLine> m_arLines;
|
||||
|
||||
public:
|
||||
CEbookParagraph() : m_arLines()
|
||||
{
|
||||
m_eType = ebitParagraph;
|
||||
m_lTextAlign = 0;
|
||||
m_lStyle = 0;
|
||||
m_lNumberingLevel = 0;
|
||||
|
||||
m_bIsPageBreakAfter = false;
|
||||
|
||||
m_bIsComplete = true;
|
||||
}
|
||||
~CEbookParagraph()
|
||||
{
|
||||
}
|
||||
CEbookParagraph(const CEbookParagraph& oSrc)
|
||||
{
|
||||
m_eType = ebitParagraph;
|
||||
*this = oSrc;
|
||||
}
|
||||
CEbookParagraph& operator=(const CEbookParagraph& oSrc)
|
||||
{
|
||||
m_lTextAlign = oSrc.m_lTextAlign;
|
||||
m_lStyle = oSrc.m_lStyle;
|
||||
m_lNumberingLevel = oSrc.m_lNumberingLevel;
|
||||
|
||||
m_arLines.RemoveAll();
|
||||
POSITION pos = oSrc.m_arLines.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CLine oLine = oSrc.m_arLines.GetNext(pos);
|
||||
m_arLines.AddTail(oLine);
|
||||
}
|
||||
m_bIsComplete = oSrc.m_bIsComplete;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
m_lTextAlign = 0;
|
||||
m_lStyle = 0;
|
||||
m_lNumberingLevel = 0;
|
||||
|
||||
m_arLines.RemoveAll();
|
||||
}
|
||||
|
||||
virtual void ReadFromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
Clear();
|
||||
|
||||
m_lTextAlign = oNode.ReadAttributeInt(_T("align"));
|
||||
m_lStyle = oNode.ReadAttributeInt(_T("style"));
|
||||
m_lNumberingLevel = oNode.ReadAttributeInt(_T("level"));
|
||||
|
||||
m_arLines.AddTail();
|
||||
CLine& oLine = m_arLines.GetTail();
|
||||
|
||||
XmlUtils::CXmlNodes oNodes;
|
||||
if (oNode.GetNodes(_T("*"), oNodes))
|
||||
{
|
||||
int nCount = oNodes.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
oLine.m_listSpans.AddTail();
|
||||
CSpan& oSpan = oLine.m_listSpans.GetTail();
|
||||
|
||||
XmlUtils::CXmlNode oNodeSpan;
|
||||
oNodes.GetAt(i, oNodeSpan);
|
||||
oSpan.FromXml(oNodeSpan);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual CString SaveToXml()
|
||||
{
|
||||
CString strHead = _T("");
|
||||
strHead.Format(_T("<p align=\"%d\" style=\"%d\" level=\"%d\">"), m_lTextAlign, m_lStyle, m_lNumberingLevel);
|
||||
|
||||
CString strPar = strHead;
|
||||
|
||||
CSpan* pSpan = NULL;
|
||||
|
||||
POSITION posLine = m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
CLine& oLine = m_arLines.GetNext(posLine);
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (NULL == pSpan)
|
||||
pSpan = &oSpan;
|
||||
else if (pSpan->m_oFont.IsEqual(&oSpan.m_oFont) && pSpan->m_oBrush.IsEqual(&oSpan.m_oBrush)
|
||||
&& (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
pSpan->m_oText += oSpan.m_oText;
|
||||
}
|
||||
else
|
||||
{
|
||||
strPar += pSpan->ToXml();
|
||||
pSpan = &oSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != pSpan)
|
||||
{
|
||||
strPar += pSpan->ToXml();
|
||||
}
|
||||
|
||||
strPar += _T("</p>");
|
||||
return strPar;
|
||||
}
|
||||
|
||||
CString GetAllText()
|
||||
{
|
||||
CString strText = _T("");
|
||||
POSITION posLine = m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CLine& oLine = m_arLines.GetNext(posLine);
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (-1 != oSpan.m_oImageInfo.m_lID)
|
||||
continue;
|
||||
|
||||
strText += oSpan.m_oText.GetCString();
|
||||
}
|
||||
}
|
||||
return strText;
|
||||
}
|
||||
|
||||
AVSINLINE bool CheckTitle()
|
||||
{
|
||||
POSITION pos = m_arLines.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CLine& oLine = m_arLines.GetNext(pos);
|
||||
if (!oLine.CheckTitle())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class CEbookNumbering : public IEbookItem
|
||||
{
|
||||
public:
|
||||
CAtlArray<CEbookParagraph> m_arParagraphs;
|
||||
LONG m_lType;
|
||||
|
||||
public:
|
||||
CEbookNumbering() : m_arParagraphs()
|
||||
{
|
||||
m_lType = ebitNumbering;
|
||||
m_bIsPageBreakAfter = false;
|
||||
}
|
||||
CEbookNumbering(const CEbookNumbering& oSrc)
|
||||
{
|
||||
m_lType = ebitNumbering;
|
||||
*this = oSrc;
|
||||
}
|
||||
CEbookNumbering& operator=(const CEbookNumbering& oSrc)
|
||||
{
|
||||
m_lType = oSrc.m_lType;
|
||||
m_arParagraphs.Copy(oSrc.m_arParagraphs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual void ReadFromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
m_arParagraphs.RemoveAll();
|
||||
|
||||
m_lType = oNode.ReadAttributeInt(_T("type"));
|
||||
XmlUtils::CXmlNodes oParagraphs;
|
||||
if (oNode.GetNodes(_T("p"), oParagraphs))
|
||||
{
|
||||
int nCount = oParagraphs.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oMem;
|
||||
oParagraphs.GetAt(i, oMem);
|
||||
m_arParagraphs.Add();
|
||||
m_arParagraphs[m_arParagraphs.GetCount() - 1].ReadFromXml(oMem);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual CString SaveToXml()
|
||||
{
|
||||
CString strXml = _T("");
|
||||
strXml.Format(_T("<num type=\"%d\">"), m_lType);
|
||||
|
||||
size_t nCount = m_arParagraphs.GetCount();
|
||||
for (size_t i = 0; i < nCount; ++i)
|
||||
{
|
||||
strXml += m_arParagraphs[i].SaveToXml();
|
||||
}
|
||||
strXml += _T("</num>");
|
||||
return strXml;
|
||||
}
|
||||
};
|
||||
}
|
||||
762
AVSEBOOKWriter2/Logic/LogicItems.h
Normal file
762
AVSEBOOKWriter2/Logic/LogicItems.h
Normal file
@ -0,0 +1,762 @@
|
||||
#pragma once
|
||||
#include "../Writers/Format.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CLogicTable : public ILogicItem
|
||||
{
|
||||
public:
|
||||
bool m_bIsEmbeddedFonts;
|
||||
LONG m_lDstFormat;
|
||||
NSEBook::CFormat* m_pFormat;
|
||||
NSCommon::CFontDstGenerator* m_pFontsDst;
|
||||
NSCommon::CFontManager* m_pFontManager;
|
||||
|
||||
CString m_strTableXml;
|
||||
public:
|
||||
CLogicTable()
|
||||
{
|
||||
m_eType = ILogicItem::elitTable;
|
||||
m_strTableXml = _T("");
|
||||
m_pFontsDst = NULL;
|
||||
m_pFontManager = NULL;
|
||||
m_pFormat = NULL;
|
||||
m_bIsEmbeddedFonts = false;
|
||||
m_lDstFormat = 0;
|
||||
}
|
||||
~CLogicTable()
|
||||
{
|
||||
}
|
||||
|
||||
virtual double GetPositionY()
|
||||
{
|
||||
return m_rcBounds.top;
|
||||
}
|
||||
virtual double GetPositionX()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LoadFromXml(CString strTable)
|
||||
{
|
||||
m_strTableXml = _T("");
|
||||
XmlUtils::CXmlNode oNode;
|
||||
if (oNode.FromXmlString(strTable))
|
||||
{
|
||||
NSCommon::CStringWriter oWriter;
|
||||
WriteTable(oNode, oWriter);
|
||||
m_strTableXml = oWriter.GetCString();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
void WriteTable(XmlUtils::CXmlNode& oNode, NSCommon::CStringWriter& oWriter)
|
||||
{
|
||||
oWriter.WriteStringC(_T("<table style=\"border-collapse:collapse;width:auto;align:left;margin-left:0cm;margin-bottom:0cm\">"));
|
||||
|
||||
XmlUtils::CXmlNode oNodeTable;
|
||||
if (oNode.GetNode(_T("fo:table-body"), oNodeTable))
|
||||
{
|
||||
XmlUtils::CXmlNodes oRows;
|
||||
if (oNodeTable.GetNodes(_T("fo:table-row"), oRows))
|
||||
{
|
||||
int nCount = oRows.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oRow;
|
||||
oRows.GetAt(i, oRow);
|
||||
WriteTR(oRow, oWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(_T("</table>"));
|
||||
}
|
||||
void WriteTR(XmlUtils::CXmlNode& oNode, NSCommon::CStringWriter& oWriter)
|
||||
{
|
||||
oWriter.WriteStringC(_T("<tr>"));
|
||||
|
||||
XmlUtils::CXmlNodes oColomns;
|
||||
if (oNode.GetNodes(_T("fo:table-cell"), oColomns))
|
||||
{
|
||||
int nCount = oColomns.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oColomn;
|
||||
oColomns.GetAt(i, oColomn);
|
||||
|
||||
CString strMergeV = oColomn.GetAttribute(_T("v-merge"));
|
||||
if (_T("continue") == strMergeV)
|
||||
continue;
|
||||
|
||||
WriteTD(oColomn, oWriter);
|
||||
}
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(_T("</tr>"));
|
||||
}
|
||||
void WriteTD(XmlUtils::CXmlNode& oNode, NSCommon::CStringWriter& oWriter)
|
||||
{
|
||||
oWriter.WriteStringC(_T("<td valign=\"top\""));
|
||||
|
||||
int colspan = oNode.ReadAttributeInt(_T("number-columns-spanned"), 1);
|
||||
int rowspan = oNode.ReadAttributeInt(_T("number-rows-spanned"), 1);
|
||||
|
||||
if (1 != colspan)
|
||||
{
|
||||
CString strMem = _T("");
|
||||
strMem.Format(_T(" colspan=\"%d\""), colspan);
|
||||
oWriter.WriteStringC(strMem);
|
||||
}
|
||||
if (1 != rowspan)
|
||||
{
|
||||
CString strMem = _T("");
|
||||
strMem.Format(_T(" rowspan=\"%d\""), rowspan);
|
||||
oWriter.WriteStringC(strMem);
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(_T(" style=\""));
|
||||
|
||||
oWriter.WriteStringC(_T("border:solid black 1.0pt;"));
|
||||
|
||||
oWriter.WriteStringC(_T("\">"));
|
||||
|
||||
XmlUtils::CXmlNodes oBlocks;
|
||||
if (oNode.GetNodes(_T("fo:block"), oBlocks))
|
||||
{
|
||||
int nCount = oBlocks.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oBlock;
|
||||
oBlocks.GetAt(i, oBlock);
|
||||
|
||||
WriteBlock(oBlock, oWriter);
|
||||
}
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(_T("</td>"));
|
||||
}
|
||||
void WriteBlock(XmlUtils::CXmlNode& oNode, NSCommon::CStringWriter& oWriter)
|
||||
{
|
||||
CString strAlign = oNode.GetAttribute(_T("text-align"), _T("left"));
|
||||
oWriter.WriteStringC(_T("<p style=\"text-align:") + strAlign + _T(";\">"));
|
||||
|
||||
XmlUtils::CXmlNodes oChilds;
|
||||
if (oNode.GetChilds(oChilds))
|
||||
{
|
||||
int nCount = oChilds.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oItem;
|
||||
oChilds.GetAt(i, oItem);
|
||||
|
||||
CString strItem = oItem.GetName();
|
||||
|
||||
if (_T("fo:inline") == strItem)
|
||||
{
|
||||
XmlUtils::CXmlNode oNodeStyle = oItem.ReadNode(_T("style-complete"));
|
||||
XmlUtils::CXmlNode oNodeText = oItem.ReadNode(_T("text"));
|
||||
|
||||
NSEBook::CEbookParagraph::CSpan oSpan;
|
||||
oSpan.m_oText += oNodeText.GetTextExt();
|
||||
|
||||
oSpan.m_oFont.Name = oNodeStyle.GetAttribute(_T("font-family"));
|
||||
oSpan.m_oFont.Bold = (_T("bold") == oNodeStyle.GetAttribute(_T("font-weight")));
|
||||
oSpan.m_oFont.Italic = (_T("italic") == oNodeStyle.GetAttribute(_T("font-style")));
|
||||
|
||||
CString strSize = oNodeStyle.GetAttribute(_T("font-size"));
|
||||
oSpan.m_oFont.Size = 0;
|
||||
if (2 < strSize.GetLength())
|
||||
{
|
||||
strSize.Delete(strSize.GetLength() - 2, 2);
|
||||
oSpan.m_oFont.Size = XmlUtils::GetDouble(strSize);
|
||||
}
|
||||
if (0 == oSpan.m_oFont.Size)
|
||||
oSpan.m_oFont.Size = 10;
|
||||
|
||||
m_pFontsDst->AddFont(&oSpan.m_oFont, true, m_pFontManager);
|
||||
|
||||
CString strStyle1 = _T("");
|
||||
CString strStyle2 = _T("");
|
||||
|
||||
if (m_bIsEmbeddedFonts)
|
||||
{
|
||||
CString strName = oSpan.m_oFont.Name;
|
||||
strName.Replace(_T(" "), _T("_avs_space_"));
|
||||
|
||||
strStyle1 = (_T("<span style=\"font-family:") + strName + _T(";"));
|
||||
if (oSpan.m_oFont.Bold)
|
||||
strStyle1 += _T("font-weight:bold;");
|
||||
else
|
||||
strStyle1 += _T("font-weight:normal;");
|
||||
|
||||
if (oSpan.m_oFont.Italic)
|
||||
strStyle1 += _T("font-style:italic;\">");
|
||||
else
|
||||
strStyle1 += _T("font-style:normal;\">");
|
||||
|
||||
strStyle2 = _T("</span>");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oSpan.m_oFont.Bold)
|
||||
{
|
||||
strStyle1 += _T("<b>");
|
||||
strStyle2 += _T("</b>");
|
||||
}
|
||||
if (oSpan.m_oFont.Italic)
|
||||
{
|
||||
strStyle1 += _T("<i>");
|
||||
strStyle2 = (_T("</i>") + strStyle2);
|
||||
}
|
||||
if (oSpan.m_oFont.Underline != 0)
|
||||
{
|
||||
strStyle1 += _T("<u>");
|
||||
strStyle2 = (_T("</u>") + strStyle2);
|
||||
}
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(strStyle1);
|
||||
if (2 != m_lDstFormat)
|
||||
{
|
||||
oWriter.WriteTextXML(oSpan.m_oText);
|
||||
}
|
||||
else
|
||||
{
|
||||
oWriter.WriteTextHTML(oSpan.m_oText);
|
||||
}
|
||||
oWriter.WriteStringC(strStyle2);
|
||||
}
|
||||
else if (_T("fo:alternate-content") == strItem)
|
||||
{
|
||||
XmlUtils::CXmlNode node1;
|
||||
if (oItem.GetNode(_T("fo:property"), node1))
|
||||
{
|
||||
XmlUtils::CXmlNode node2;
|
||||
if (node1.GetNode(_T("fo:graphic"), node2))
|
||||
{
|
||||
XmlUtils::CXmlNode node3;
|
||||
if (node2.GetNode(_T("fo:source"), node3))
|
||||
{
|
||||
CString strFile = node3.GetAttribute(_T("dir"));
|
||||
strFile += _T("\\word\\");
|
||||
CString strName = node3.GetTextExt();
|
||||
strName.Replace(TCHAR('/'), TCHAR('\\'));
|
||||
|
||||
strFile += strName;
|
||||
|
||||
CFile oFile;
|
||||
HRESULT hr = oFile.OpenFile(strFile);
|
||||
oFile.CloseFile();
|
||||
|
||||
if (S_OK == hr)
|
||||
{
|
||||
double _x = 0;
|
||||
double _y = 0;
|
||||
double _w = 10000;
|
||||
double _h = 10000;
|
||||
|
||||
NSCommon::CImageInfo oInfo = m_pFormat->m_oImageManager.WriteImage(strFile, _x, _y, _w, _h);
|
||||
|
||||
if (0 == m_lDstFormat)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<img src=\"media/image%d.%s\" alt=\"\"/>"), oInfo.m_lID,
|
||||
(NSCommon::itJPG == oInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
oWriter.WriteStringC(strImage);
|
||||
}
|
||||
else if (1 == m_lDstFormat)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<image xlink:href=\"#image%d.%s\"/>"), oInfo.m_lID,
|
||||
(NSCommon::itJPG == oInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
oWriter.WriteStringC(strImage);
|
||||
}
|
||||
else if (2 == m_lDstFormat)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<img recindex=\"%d\" align=\"baseline\" alt=\"\"/>"), oInfo.m_lID);
|
||||
oWriter.WriteStringC(strImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oWriter.WriteStringC(_T("</p>"));
|
||||
}
|
||||
};
|
||||
|
||||
class IGraphicCommand
|
||||
{
|
||||
public:
|
||||
enum EGraphicCommandType
|
||||
{
|
||||
egctPath = 0,
|
||||
egctText = 1
|
||||
};
|
||||
|
||||
public:
|
||||
EGraphicCommandType m_eType;
|
||||
|
||||
public:
|
||||
IGraphicCommand()
|
||||
{
|
||||
m_eType = egctPath;
|
||||
}
|
||||
};
|
||||
|
||||
class CItemPath : public IGraphicCommand
|
||||
{
|
||||
private:
|
||||
class CPathMeta
|
||||
{
|
||||
private:
|
||||
enum PathCommand
|
||||
{
|
||||
// pathcommands
|
||||
pcMoveTo = 0,
|
||||
pcLineTo = 1,
|
||||
pcCurveTo = 2,
|
||||
pcClose = 3
|
||||
};
|
||||
private:
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE* m_pBuffer;
|
||||
BYTE* m_pBufferMem;
|
||||
|
||||
size_t m_lPosition;
|
||||
size_t m_lSize;
|
||||
|
||||
public:
|
||||
CPathMeta()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
~CPathMeta()
|
||||
{
|
||||
RELEASEARRAYOBJECTS(m_pBuffer);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
m_lSize = 0;
|
||||
m_lPosition = 0;
|
||||
|
||||
m_pBuffer = NULL;
|
||||
}
|
||||
|
||||
AVSINLINE void CheckBufferSize(size_t lPlus)
|
||||
{
|
||||
if (NULL != m_pBuffer)
|
||||
{
|
||||
size_t nNewSize = m_lPosition + lPlus;
|
||||
|
||||
if (nNewSize >= m_lSize)
|
||||
{
|
||||
while (nNewSize >= m_lSize)
|
||||
{
|
||||
m_lSize *= 2;
|
||||
}
|
||||
|
||||
BYTE* pNew = new BYTE[m_lSize];
|
||||
memcpy(pNew, m_pBuffer, m_lPosition);
|
||||
|
||||
RELEASEARRAYOBJECTS(m_pBuffer);
|
||||
m_pBuffer = pNew;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lSize = 1000;
|
||||
m_pBuffer = new BYTE[m_lSize];
|
||||
|
||||
CheckBufferSize(lPlus);
|
||||
}
|
||||
}
|
||||
|
||||
AVSINLINE void WriteCommandType(const PathCommand& eType)
|
||||
{
|
||||
CheckBufferSize(sizeof(BYTE));
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eType;
|
||||
m_lPosition += sizeof(BYTE);
|
||||
}
|
||||
inline void WriteDouble(const double& dValue)
|
||||
{
|
||||
CheckBufferSize(sizeof(double));
|
||||
|
||||
*((double*)(m_pBuffer + m_lPosition)) = dValue;
|
||||
m_lPosition += sizeof(double);
|
||||
}
|
||||
inline void WriteBYTE(const PathCommand& eType, const BYTE& lValue)
|
||||
{
|
||||
CheckBufferSize(2 * sizeof(BYTE));
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eType;
|
||||
m_lPosition += sizeof(BYTE);
|
||||
|
||||
*(m_pBuffer + m_lPosition) = lValue;
|
||||
m_lPosition += sizeof(BYTE);
|
||||
}
|
||||
inline void WriteLONG(const PathCommand& eType, const LONG& lValue)
|
||||
{
|
||||
CheckBufferSize(sizeof(BYTE) + sizeof(LONG));
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eType;
|
||||
m_lPosition += sizeof(BYTE);
|
||||
|
||||
*((LONG*)(m_pBuffer + m_lPosition)) = lValue;
|
||||
m_lPosition += sizeof(LONG);
|
||||
}
|
||||
inline void WriteDouble(const PathCommand& eType, const double& dValue)
|
||||
{
|
||||
CheckBufferSize(sizeof(BYTE) + sizeof(double));
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eType;
|
||||
m_lPosition += sizeof(BYTE);
|
||||
|
||||
*((double*)(m_pBuffer + m_lPosition)) = dValue;
|
||||
m_lPosition += sizeof(double);
|
||||
}
|
||||
inline void Write(const PathCommand& eCommand, const double& f1, const double& f2)
|
||||
{
|
||||
size_t lMem = sizeof(BYTE) + 2 * sizeof(double);
|
||||
|
||||
CheckBufferSize(lMem);
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += sizeof(BYTE);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f1; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f2; m_lPosition += sizeof(double);
|
||||
}
|
||||
|
||||
inline void Write(const PathCommand& eCommand, const double& f1, const double& f2, const double& f3, const double& f4, const double& f5, const double& f6)
|
||||
{
|
||||
size_t lMem = sizeof(BYTE) + 6 * sizeof(double);
|
||||
|
||||
CheckBufferSize(lMem);
|
||||
|
||||
*(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += sizeof(BYTE);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f1; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f2; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f3; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f4; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f5; m_lPosition += sizeof(double);
|
||||
*((double*)(m_pBuffer + m_lPosition))= f6; m_lPosition += sizeof(double);
|
||||
}
|
||||
public:
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
AVSINLINE void _MoveTo(double fX, double fY)
|
||||
{
|
||||
Write(pcMoveTo, fX, fY);
|
||||
}
|
||||
AVSINLINE void _LineTo(double fX, double fY)
|
||||
{
|
||||
Write(pcLineTo, fX, fY);
|
||||
}
|
||||
AVSINLINE void _CurveTo(double fX1, double fY1, double fX2, double fY2, double fX3, double fY3)
|
||||
{
|
||||
Write(pcCurveTo, fX1, fY1, fX2, fY2, fX3, fY3);
|
||||
}
|
||||
AVSINLINE void _Close()
|
||||
{
|
||||
WriteCommandType(pcClose);
|
||||
}
|
||||
public:
|
||||
AVSINLINE LONG ReadLONG()
|
||||
{
|
||||
LONG l = *((LONG*)m_pBufferMem);
|
||||
m_pBufferMem += sizeof(LONG);
|
||||
return l;
|
||||
}
|
||||
AVSINLINE BYTE ReadByte()
|
||||
{
|
||||
BYTE l = *m_pBufferMem;
|
||||
++m_pBufferMem;
|
||||
return l;
|
||||
}
|
||||
AVSINLINE double ReadDouble()
|
||||
{
|
||||
double l = *((double*)m_pBufferMem);
|
||||
m_pBufferMem += sizeof(double);
|
||||
return l;
|
||||
}
|
||||
public:
|
||||
BOOL Draw(IAVSRenderer* pRenderer)
|
||||
{
|
||||
if (NULL == pRenderer)
|
||||
return FALSE;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...
|
||||
m_pBufferMem = m_pBuffer;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...
|
||||
// (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> - <20> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (!!!) <20><><EFBFBD>)
|
||||
PathCommand eCurCommand;
|
||||
|
||||
HRESULT hRes = S_OK;
|
||||
while (m_lPosition > ((size_t)(m_pBufferMem - m_pBuffer)))
|
||||
{
|
||||
eCurCommand = (PathCommand)ReadByte();
|
||||
|
||||
switch (eCurCommand)
|
||||
{
|
||||
case pcMoveTo:
|
||||
{
|
||||
double fX = ReadDouble();
|
||||
double fY = ReadDouble();
|
||||
|
||||
hRes = pRenderer->PathCommandMoveTo(fX, fY);
|
||||
|
||||
break;
|
||||
}
|
||||
case pcLineTo:
|
||||
{
|
||||
double fX = ReadDouble();
|
||||
double fY = ReadDouble();
|
||||
|
||||
hRes = pRenderer->PathCommandLineTo(fX, fY);
|
||||
|
||||
break;
|
||||
}
|
||||
case pcCurveTo:
|
||||
{
|
||||
double fX1 = ReadDouble();
|
||||
double fY1 = ReadDouble();
|
||||
double fX2 = ReadDouble();
|
||||
double fY2 = ReadDouble();
|
||||
double fX3 = ReadDouble();
|
||||
double fY3 = ReadDouble();
|
||||
|
||||
hRes = pRenderer->PathCommandCurveTo(fX1, fY1, fX2, fY2, fX3, fY3);
|
||||
|
||||
break;
|
||||
}
|
||||
case pcClose:
|
||||
{
|
||||
hRes = pRenderer->PathCommandClose();
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
return FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
if (S_OK != hRes)
|
||||
break;
|
||||
}
|
||||
return (S_OK == hRes);
|
||||
}
|
||||
};
|
||||
public:
|
||||
NSStructures::CPen m_oPen;
|
||||
NSStructures::CBrush m_oBrush;
|
||||
|
||||
LONG m_lType;
|
||||
CDoubleRect m_rcBounds;
|
||||
CPathMeta m_oGeometry;
|
||||
|
||||
public:
|
||||
CItemPath()
|
||||
{
|
||||
m_rcBounds.left = 50000;
|
||||
m_rcBounds.right = -1;
|
||||
m_rcBounds.top = 50000;
|
||||
m_rcBounds.bottom = -1;
|
||||
}
|
||||
~CItemPath()
|
||||
{
|
||||
}
|
||||
};
|
||||
class CItemText
|
||||
{
|
||||
public:
|
||||
NSStructures::CBrush m_oBrush;
|
||||
NSStructures::CFont m_oFont;
|
||||
_bstr_t m_bsText;
|
||||
_bstr_t m_bsGid;
|
||||
|
||||
public:
|
||||
CItemText() : m_bsText(), m_bsGid()
|
||||
{
|
||||
}
|
||||
~CItemText()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class CLogicGraphic : public ILogicItem
|
||||
{
|
||||
public:
|
||||
CAtlList<IGraphicCommand*> m_arCommands;
|
||||
|
||||
public:
|
||||
CLogicGraphic()
|
||||
{
|
||||
m_eType = ILogicItem::elitGraphic;
|
||||
}
|
||||
~CLogicGraphic()
|
||||
{
|
||||
}
|
||||
|
||||
virtual double GetPositionY()
|
||||
{
|
||||
return m_rcBounds.top;
|
||||
}
|
||||
virtual double GetPositionX()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
class CLogicImage : public ILogicItem
|
||||
{
|
||||
public:
|
||||
CImageInfo m_oImageInfo;
|
||||
|
||||
public:
|
||||
CLogicImage()
|
||||
{
|
||||
m_oImageInfo.m_lID = -1;
|
||||
m_eType = ILogicItem::elitGraphic;
|
||||
}
|
||||
~CLogicImage()
|
||||
{
|
||||
}
|
||||
|
||||
virtual double GetPositionY()
|
||||
{
|
||||
return m_rcBounds.top;
|
||||
}
|
||||
virtual double GetPositionX()
|
||||
{
|
||||
return m_rcBounds.left;
|
||||
}
|
||||
};
|
||||
|
||||
class CLogicParagraph : public ILogicItem
|
||||
{
|
||||
public:
|
||||
CEbookParagraph m_oParagraph;
|
||||
|
||||
public:
|
||||
CLogicParagraph()
|
||||
{
|
||||
m_eType = elitTextParagraph;
|
||||
}
|
||||
CLogicParagraph(const CEbookParagraph& oSrc)
|
||||
{
|
||||
m_eType = elitTextParagraph;
|
||||
m_oParagraph = oSrc;
|
||||
}
|
||||
~CLogicParagraph()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual double GetPositionY()
|
||||
{
|
||||
return m_rcBounds.top;
|
||||
}
|
||||
virtual double GetPositionX()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class ILogicPage
|
||||
{
|
||||
public:
|
||||
NSStructures::CPen* m_pPen;
|
||||
NSStructures::CBrush* m_pBrush;
|
||||
NSStructures::CFont* m_pFont;
|
||||
NSStructures::CShadow* m_pShadow;
|
||||
NSStructures::CEdgeText* m_pEdgeText;
|
||||
|
||||
NSCommon::CMatrix* m_pTransform;
|
||||
AVSGraphics::IAVSGraphicSimpleComverter* m_pSimpleGraphicsConverter;
|
||||
|
||||
double m_dWidth;
|
||||
double m_dHeight;
|
||||
|
||||
CImageManager m_oManager;
|
||||
|
||||
LONG m_lCurrentCommand;
|
||||
CAtlList<ILogicItem*> m_arItems;
|
||||
|
||||
CImageManager* m_pImageManager;
|
||||
|
||||
NSCommon::CFontDstGenerator m_oFontsGen;
|
||||
NSCommon::CFontManager m_oFontManager;
|
||||
|
||||
CImageInfo m_oInfoWatermark;
|
||||
CDoubleRect m_oRectWatermark;
|
||||
bool m_bIsDumpWatermark;
|
||||
|
||||
public:
|
||||
|
||||
virtual void ConvertToEbookPage(NSEBook::CFormat& oFormat) = 0;
|
||||
virtual void Clear() = 0;
|
||||
|
||||
virtual void MoveTo(double& x, double& y) = 0;
|
||||
virtual void LineTo(double& x, double& y) = 0;
|
||||
virtual void CurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3) = 0;
|
||||
virtual void Close() = 0;
|
||||
virtual void BeginPath() = 0;
|
||||
virtual void EndPath() = 0;
|
||||
virtual void DrawPath(LONG lType) = 0;
|
||||
|
||||
virtual void WriteText(BSTR& bsText, BSTR& bsGid, double& x, double& y, double& width, double& height, double& baselineoffset) = 0;
|
||||
|
||||
virtual void WriteTable(NSEBook::ILogicItem* pItem) = 0;
|
||||
virtual void BeginShape() = 0;
|
||||
virtual void EndShape() = 0;
|
||||
|
||||
virtual void WriteImage(IUnknown* punkImage, double& x, double& y, double& width, double& height) = 0;
|
||||
virtual void WriteImage(CString strFilePath, double& x, double& y, double& width, double& height) = 0;
|
||||
|
||||
virtual void BeginPage() = 0;
|
||||
virtual void EndPage() = 0;
|
||||
virtual void CloseFile(NSEBook::CFormat& oFormat) = 0;
|
||||
|
||||
virtual void InitProp() = 0;
|
||||
virtual void WritePagePreak()
|
||||
{
|
||||
if (0 == m_arItems.GetCount())
|
||||
return;
|
||||
|
||||
ILogicItem* pItem = m_arItems.GetTail();
|
||||
if (NULL != pItem)
|
||||
pItem->m_bIsPageBreakAfter = true;
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void CheckWatermark(CFormat& oFormat)
|
||||
{
|
||||
if (m_bIsDumpWatermark && (-1 != m_oInfoWatermark.m_lID))
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> watermark
|
||||
CEbookGraphicObject* pObject = new CEbookGraphicObject();
|
||||
pObject->m_oInfo = m_oInfoWatermark;
|
||||
pObject->m_rcBounds = m_oRectWatermark;
|
||||
|
||||
if (0 == oFormat.m_listSections.GetCount())
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
oFormat.m_listSections.AddTail();
|
||||
}
|
||||
CSection& oSection = oFormat.m_listSections.GetTail();
|
||||
oSection.m_arItems.AddTail(pObject);
|
||||
}
|
||||
m_bIsDumpWatermark = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
0
AVSEBOOKWriter2/Logic/LogicPage.cpp
Normal file
0
AVSEBOOKWriter2/Logic/LogicPage.cpp
Normal file
3
AVSEBOOKWriter2/Logic/LogicPage.h
Normal file
3
AVSEBOOKWriter2/Logic/LogicPage.h
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
#include "LogicPagePDF.h"
|
||||
#include "LogicPageDOCX.h"
|
||||
883
AVSEBOOKWriter2/Logic/LogicPageDOCX.h
Normal file
883
AVSEBOOKWriter2/Logic/LogicPageDOCX.h
Normal file
@ -0,0 +1,883 @@
|
||||
#pragma once
|
||||
#include "LogicItems.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CBaseWriter
|
||||
{
|
||||
public:
|
||||
virtual void WriteShape(IUnknown* punkImage, double& x, double& y, double& width, double& height) = 0;
|
||||
};
|
||||
|
||||
|
||||
const double c_dSpaceW = 0.5;
|
||||
class CTextSmart
|
||||
{
|
||||
public:
|
||||
CFontManager* m_pFontManager;
|
||||
CFontDstGenerator* m_pFontsDst;
|
||||
|
||||
double m_dDpiX;
|
||||
double m_dDpiY;
|
||||
|
||||
NSStructures::CPen* m_pPen;
|
||||
NSStructures::CBrush* m_pBrush;
|
||||
NSStructures::CFont* m_pFont;
|
||||
|
||||
NSCommon::CMatrix* m_pTransform;
|
||||
|
||||
CEbookParagraph m_oParagraph;
|
||||
CTextItem m_oTextItem;
|
||||
|
||||
private:
|
||||
double m_dEpsX;
|
||||
double m_dEpsY;
|
||||
|
||||
public:
|
||||
CTextSmart() : m_pFontManager(NULL), m_oTextItem(10)
|
||||
{
|
||||
m_dEpsX = 0.5;
|
||||
m_dEpsY = 0.5;
|
||||
|
||||
m_pPen = NULL;
|
||||
m_pBrush = NULL;
|
||||
m_pFont = NULL;
|
||||
|
||||
m_pTransform = NULL;
|
||||
|
||||
m_pFontsDst = NULL;
|
||||
}
|
||||
|
||||
void SetParams(NSStructures::CPen* pPen, NSStructures::CBrush* pBrush, NSStructures::CFont* pFont, NSCommon::CMatrix* pTransform)
|
||||
{
|
||||
m_pPen = pPen;
|
||||
m_pBrush = pBrush;
|
||||
m_pFont = pFont;
|
||||
|
||||
m_pFontManager->m_pFont = pFont;
|
||||
m_pFontManager->m_pTransform = pTransform;
|
||||
m_pTransform = pTransform;
|
||||
}
|
||||
|
||||
~CTextSmart()
|
||||
{
|
||||
}
|
||||
|
||||
void NewPage(double& dDpiX, double& dDpiY)
|
||||
{
|
||||
m_dDpiX = dDpiX;
|
||||
m_dDpiY = dDpiY;
|
||||
|
||||
m_pPen->SetDefaultParams();
|
||||
m_pBrush->SetDefaultParams();
|
||||
m_pFont->SetDefaultParams();
|
||||
|
||||
m_oParagraph.Clear();
|
||||
}
|
||||
|
||||
void NewDocument()
|
||||
{
|
||||
m_pPen->SetDefaultParams();
|
||||
m_pBrush->SetDefaultParams();
|
||||
m_pFont->SetDefaultParams();
|
||||
}
|
||||
|
||||
CEbookParagraph::CLine& GetCurrentLine()
|
||||
{
|
||||
if (0 == m_oParagraph.m_arLines.GetCount())
|
||||
m_oParagraph.m_arLines.AddTail();
|
||||
|
||||
return m_oParagraph.m_arLines.GetTail();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void CommandText(double& x, double& y, double& width, double& height, double& baselineoffset, double& dCurrentBaselineOffset)
|
||||
{
|
||||
double dScaleFont = ((m_pTransform->m_agg_mtx.sx + m_pTransform->m_agg_mtx.sy) / 2);
|
||||
BOOL bIsFontChanged = !m_pFontManager->m_oFont.m_oFont.IsEqual2(m_pFont, dScaleFont);
|
||||
|
||||
BOOL bIsTextDecorationChanged = ((m_pFontManager->m_oFont.m_oFont.Underline != m_pFont->Underline) ||
|
||||
(m_pFontManager->m_oFont.m_oFont.Strikeout != m_pFont->Strikeout));
|
||||
|
||||
if (bIsFontChanged)
|
||||
{
|
||||
m_pFontManager->m_oFont.m_oFont = *m_pFont;
|
||||
m_pFontManager->m_oFont.m_oFont.Size *= dScaleFont;
|
||||
}
|
||||
else if (bIsTextDecorationChanged)
|
||||
{
|
||||
m_pFontManager->m_oFont.m_oFont.Underline = m_pFont->Underline;
|
||||
m_pFontManager->m_oFont.m_oFont.Strikeout = m_pFont->Strikeout;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> m_pFont
|
||||
m_pFontManager->m_strCurrentPickFont = _T("");
|
||||
|
||||
if (0 == width)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>?? <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>??
|
||||
m_pFontManager->LoadCurrentFont();
|
||||
|
||||
double dOffset = m_pFontManager->m_oFont.m_dBaselineOffsetHTML;
|
||||
dOffset *= (m_dDpiY / 72.0);
|
||||
|
||||
y -= dOffset;
|
||||
baselineoffset = dOffset;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
double _x = 0;
|
||||
double _y = 0;
|
||||
double _w = 0;
|
||||
double _h = 0;
|
||||
|
||||
LONG lGid = m_pFontManager->GetStringGid();
|
||||
m_pFontManager->SetStringGid(0);
|
||||
m_pFontManager->MeasureStringPix(m_oTextItem.GetCString(), x, y, _x, _y, _w, _h, CFontManager::MeasureTypePosition);
|
||||
m_pFontManager->SetStringGid(lGid);
|
||||
|
||||
width = _w;
|
||||
height = _h;
|
||||
}
|
||||
|
||||
CEbookParagraph::CLine& oCurrentLine = GetCurrentLine();
|
||||
|
||||
double dYPos = y + baselineoffset;
|
||||
LONG lCountWords = (LONG)oCurrentLine.m_listSpans.GetCount();
|
||||
|
||||
m_pFontsDst->AddFont(m_pFont, bIsFontChanged, m_pFontManager);
|
||||
if (0 == lCountWords)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>, <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
oCurrentLine.m_listSpans.AddTail();
|
||||
CEbookParagraph::CSpan& oSpan = oCurrentLine.m_listSpans.GetTail();
|
||||
|
||||
//oSpan.m_oFont = m_oFontManager.m_oFont.m_oFont;
|
||||
//oSpan.m_oFont.Name = m_oFontManager.m_strCurrentPickFont;
|
||||
//oSpan.m_oFont.SetStyle(m_oFontManager.m_lCurrentPictFontStyle);
|
||||
oSpan.m_oFont = *m_pFont;
|
||||
|
||||
oSpan.m_oBrush = *m_pBrush;
|
||||
oSpan.m_oText = m_oTextItem;
|
||||
oSpan.m_dX = x;
|
||||
oSpan.m_dWidthSpan = width;
|
||||
oSpan.m_dBaselineOffset = dCurrentBaselineOffset;
|
||||
return;
|
||||
}
|
||||
|
||||
CEbookParagraph::CSpan& oTail = oCurrentLine.m_listSpans.GetTail();
|
||||
double dRight = oTail.m_dX + oTail.m_dWidthSpan;
|
||||
if (oTail.m_oImageInfo.m_lID != -1)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
oCurrentLine.m_listSpans.AddTail();
|
||||
CEbookParagraph::CSpan& oSpan = oCurrentLine.m_listSpans.GetTail();
|
||||
|
||||
//oSpan.m_oFont = m_oFontManager.m_oFont.m_oFont;
|
||||
//oSpan.m_oFont.Name = m_oFontManager.m_strCurrentPickFont;
|
||||
//oSpan.m_oFont.SetStyle(m_oFontManager.m_lCurrentPictFontStyle);
|
||||
oSpan.m_oFont = *m_pFont;
|
||||
|
||||
oSpan.m_oBrush = *m_pBrush;
|
||||
oSpan.m_oText = m_oTextItem;
|
||||
oSpan.m_dX = x;
|
||||
oSpan.m_dWidthSpan = width;
|
||||
oSpan.m_dBaselineOffset = dCurrentBaselineOffset;
|
||||
|
||||
if (c_dSpaceW < FABS(oTail.m_dX + oTail.m_dWidthSpan - x))
|
||||
{
|
||||
// <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>!!!
|
||||
oSpan.m_oText.AddSpaceFirst();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (!bIsFontChanged && oTail.m_oBrush.IsEqual(m_pBrush) && !bIsTextDecorationChanged && (oTail.m_dBaselineOffset == dCurrentBaselineOffset))
|
||||
{
|
||||
if (c_dSpaceW < FABS(oTail.m_dX + oTail.m_dWidthSpan - x))
|
||||
{
|
||||
// <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>!!!
|
||||
oTail.m_oText.AddSpace();
|
||||
}
|
||||
|
||||
oTail.m_oText += m_oTextItem;
|
||||
oTail.m_dWidthSpan = (x + width - oTail.m_dX);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c_dSpaceW < FABS(oTail.m_dX + oTail.m_dWidthSpan - x))
|
||||
{
|
||||
// <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>!!!
|
||||
oTail.m_oText.AddSpace();
|
||||
}
|
||||
|
||||
oCurrentLine.m_listSpans.AddTail();
|
||||
CEbookParagraph::CSpan& oSpan = oCurrentLine.m_listSpans.GetTail();
|
||||
|
||||
//oSpan.m_oFont = m_oFontManager.m_oFont.m_oFont;
|
||||
//oSpan.m_oFont.Name = m_oFontManager.m_strCurrentPickFont;
|
||||
//oSpan.m_oFont.SetStyle(m_oFontManager.m_lCurrentPictFontStyle);
|
||||
oSpan.m_oFont = *m_pFont;
|
||||
|
||||
oSpan.m_oBrush = *m_pBrush;
|
||||
oSpan.m_oText = m_oTextItem;
|
||||
oSpan.m_dX = x;
|
||||
oSpan.m_dWidthSpan = width;
|
||||
oSpan.m_dBaselineOffset = dCurrentBaselineOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
AVSINLINE void CommandText(BSTR& bsText, BSTR& bsGid, double& x, double& y, double& width, double& height, double& baselineoffset, double& dCurrentBaselineOffset)
|
||||
{
|
||||
if (NULL == bsText)
|
||||
return;
|
||||
|
||||
m_oTextItem.SetText(bsText);
|
||||
|
||||
if (0 == m_oTextItem.GetCurSize())
|
||||
return;
|
||||
|
||||
m_oParagraph.m_rcBounds.top = min(m_oParagraph.m_rcBounds.top, y);
|
||||
m_oParagraph.m_rcBounds.bottom = max(m_oParagraph.m_rcBounds.bottom, y);
|
||||
|
||||
return CommandText(x, y, width, height, baselineoffset, dCurrentBaselineOffset);
|
||||
}
|
||||
};
|
||||
|
||||
class CLogicPageDOCX : public ILogicPage, public CBaseWriter
|
||||
{
|
||||
public:
|
||||
class CLogicShape
|
||||
{
|
||||
public:
|
||||
CDoubleRect m_rcBounds;
|
||||
MediaCore::IAVSUncompressedVideoFrame* m_pFrame;
|
||||
AVSGraphics::IAVSGraphicsRenderer* m_pGraphicsRenderer;
|
||||
|
||||
public:
|
||||
CLogicShape()
|
||||
{
|
||||
m_rcBounds.ClearBounds();
|
||||
|
||||
m_pFrame = NULL;
|
||||
m_pGraphicsRenderer = NULL;
|
||||
}
|
||||
~CLogicShape()
|
||||
{
|
||||
RELEASEINTERFACE(m_pFrame);
|
||||
RELEASEINTERFACE(m_pGraphicsRenderer);
|
||||
}
|
||||
void Clear()
|
||||
{
|
||||
m_rcBounds.ClearBounds();
|
||||
RELEASEINTERFACE(m_pGraphicsRenderer);
|
||||
}
|
||||
void CreateShape(double& dWidth, double& dHeight)
|
||||
{
|
||||
Clear();
|
||||
|
||||
LONG lWidthCur = (LONG)(96.0 * dWidth / 25.4);
|
||||
LONG lHeightCur = (LONG)(96.0 * dHeight / 25.4);
|
||||
|
||||
bool bIsNeedCreate = true;
|
||||
if (NULL != m_pFrame)
|
||||
{
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
m_pFrame->get_Width(&lWidth);
|
||||
m_pFrame->get_Height(&lHeight);
|
||||
|
||||
if ((lWidthCur == lWidth) && (lHeightCur == lHeight))
|
||||
bIsNeedCreate = false;
|
||||
}
|
||||
|
||||
if (bIsNeedCreate)
|
||||
{
|
||||
RELEASEINTERFACE(m_pFrame);
|
||||
|
||||
CoCreateInstance(MediaCore::CLSID_CAVSUncompressedVideoFrame, NULL, CLSCTX_ALL,
|
||||
MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&m_pFrame);
|
||||
|
||||
m_pFrame->put_ColorSpace( ( 1 << 6) | ( 1 << 31) ); // CPS_BGRA | CPS_FLIP
|
||||
m_pFrame->put_Width( lWidthCur );
|
||||
m_pFrame->put_Height( lHeightCur );
|
||||
m_pFrame->put_AspectRatioX( lWidthCur );
|
||||
m_pFrame->put_AspectRatioY( lHeightCur );
|
||||
m_pFrame->put_Interlaced( VARIANT_FALSE );
|
||||
m_pFrame->put_Stride( 0, 4 * lWidthCur );
|
||||
m_pFrame->AllocateBuffer( -1 );
|
||||
}
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
m_pFrame->get_Buffer(&pBuffer);
|
||||
memset(pBuffer, 0xFF, 4 * lWidthCur * lHeightCur);
|
||||
|
||||
CoCreateInstance(AVSGraphics::CLSID_CAVSGraphicsRenderer, NULL, CLSCTX_ALL,
|
||||
AVSGraphics::IID_IAVSGraphicsRenderer, (void**)&m_pGraphicsRenderer);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FontManager
|
||||
VARIANT vtVariant;
|
||||
vtVariant.vt = VT_UNKNOWN;
|
||||
vtVariant.punkVal = NULL;
|
||||
m_pGraphicsRenderer->SetAdditionalParam( L"FontManager", vtVariant );
|
||||
|
||||
m_pGraphicsRenderer->put_Width(dWidth);
|
||||
m_pGraphicsRenderer->put_Height(dHeight);
|
||||
m_pGraphicsRenderer->CreateFromMediaData((IUnknown*)m_pFrame, 0, 0, lWidthCur, lHeightCur );
|
||||
}
|
||||
void GetShape(CBaseWriter* pBaseWriter)
|
||||
{
|
||||
LONG lWidthCur = 0;
|
||||
LONG lHeightCur = 0;
|
||||
m_pFrame->get_Width(&lWidthCur);
|
||||
m_pFrame->get_Height(&lHeightCur);
|
||||
|
||||
LONG lLeft = max(0, min(lWidthCur - 1, (LONG)(m_rcBounds.left * 96.0 / 25.4)));
|
||||
LONG lTop = max(0, min(lHeightCur - 1, (LONG)(m_rcBounds.top * 96.0 / 25.4)));
|
||||
LONG lRight = max(0, min(lWidthCur - 1, (LONG)(m_rcBounds.right * 96.0 / 25.4)));
|
||||
LONG lBottom = max(0, min(lHeightCur - 1, (LONG)(m_rcBounds.bottom * 96.0 / 25.4)));
|
||||
|
||||
if (lRight < lLeft || lBottom < lTop)
|
||||
return;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pShapePicture = NULL;
|
||||
CoCreateInstance(MediaCore::CLSID_CAVSUncompressedVideoFrame, NULL, CLSCTX_ALL,
|
||||
MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pShapePicture);
|
||||
|
||||
LONG lWidthShape = lRight - lLeft + 1;
|
||||
LONG lHeightShape = lBottom - lTop + 1;
|
||||
|
||||
pShapePicture->put_ColorSpace( ( 1 << 6) | ( 1 << 31) ); // CPS_BGRA | CPS_FLIP
|
||||
pShapePicture->put_Width( lWidthShape );
|
||||
pShapePicture->put_Height( lHeightShape );
|
||||
pShapePicture->put_AspectRatioX( lWidthShape );
|
||||
pShapePicture->put_AspectRatioY( lHeightShape );
|
||||
pShapePicture->put_Interlaced( VARIANT_FALSE );
|
||||
pShapePicture->put_Stride( 0, 4 * lWidthShape );
|
||||
pShapePicture->AllocateBuffer( -1 );
|
||||
|
||||
BYTE* pBufferDst = NULL;
|
||||
pShapePicture->get_Buffer(&pBufferDst);
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
m_pFrame->get_Buffer(&pBuffer);
|
||||
|
||||
BYTE* pDstLine = pBufferDst;
|
||||
BYTE* pSrcLine = pBuffer + 4 * (lHeightCur - 1 - lBottom) * lWidthCur + lLeft * 4;
|
||||
|
||||
for (int ind = 0; ind < lHeightShape; ++ind)
|
||||
{
|
||||
memcpy(pDstLine, pSrcLine, 4 * lWidthShape);
|
||||
pDstLine += (4 * lWidthShape);
|
||||
pSrcLine += (4 * lWidthCur);
|
||||
}
|
||||
|
||||
double __x = m_rcBounds.left;
|
||||
double __y = m_rcBounds.top;
|
||||
double __w = m_rcBounds.right - __x;
|
||||
double __h = m_rcBounds.bottom - __y;
|
||||
|
||||
pBaseWriter->WriteShape((IUnknown*)pShapePicture, __x, __y, __w, __h);
|
||||
|
||||
RELEASEINTERFACE(pShapePicture);
|
||||
}
|
||||
|
||||
|
||||
AVSINLINE void MoveTo(double& x, double& y)
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandMoveTo(x, y);
|
||||
m_rcBounds.CheckBounds(x, y);
|
||||
}
|
||||
AVSINLINE void LineTo(double& x, double& y)
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandLineTo(x, y);
|
||||
m_rcBounds.CheckBounds(x, y);
|
||||
}
|
||||
AVSINLINE void CurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandCurveTo(x1, y1, x2, y2, x3, y3);
|
||||
m_rcBounds.CheckBounds(x1, y1);
|
||||
m_rcBounds.CheckBounds(x2, y2);
|
||||
m_rcBounds.CheckBounds(x3, y3);
|
||||
}
|
||||
AVSINLINE void Close()
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandClose();
|
||||
}
|
||||
AVSINLINE void BeginPath()
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandStart();
|
||||
}
|
||||
AVSINLINE void EndPath()
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
m_pGraphicsRenderer->PathCommandEnd();
|
||||
}
|
||||
|
||||
AVSINLINE void WriteText(BSTR& bsText, BSTR& bsGid, double& x, double& y, double& width, double& height, double& baselineoffset,
|
||||
NSStructures::CFont* pFont, NSStructures::CBrush* pBrush)
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
{
|
||||
pFont->SetToRenderer((IAVSRenderer*)m_pGraphicsRenderer);
|
||||
pBrush->SetToRenderer((IAVSRenderer*)m_pGraphicsRenderer);
|
||||
|
||||
if (NULL == bsGid)
|
||||
m_pGraphicsRenderer->CommandDrawText(bsText, x, y, width, height, baselineoffset);
|
||||
else
|
||||
m_pGraphicsRenderer->CommandDrawTextEx(bsText, bsGid, NULL, x, y, width, height, baselineoffset, 0);
|
||||
}
|
||||
|
||||
m_rcBounds.CheckBounds(x, y);
|
||||
m_rcBounds.CheckBounds(x + width, y + height);
|
||||
}
|
||||
AVSINLINE void DrawPath(LONG lPath, NSStructures::CPen* pPen, NSStructures::CBrush* pBrush)
|
||||
{
|
||||
if (NULL != m_pGraphicsRenderer)
|
||||
{
|
||||
pPen->SetToRenderer((IAVSRenderer*)m_pGraphicsRenderer);
|
||||
pBrush->SetToRenderer((IAVSRenderer*)m_pGraphicsRenderer);
|
||||
m_pGraphicsRenderer->DrawPath(lPath);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
CLogicShape m_oCurrentShape;
|
||||
LONG m_lShapeTop;
|
||||
|
||||
CTextSmart m_oText;
|
||||
bool m_bIsPar;
|
||||
double m_dCurrentBaselineOffset;
|
||||
|
||||
double m_dLastTop;
|
||||
|
||||
public:
|
||||
CLogicPageDOCX() : ILogicPage()
|
||||
{
|
||||
m_lShapeTop = 0;
|
||||
m_bIsPar = false;
|
||||
}
|
||||
~CLogicPageDOCX()
|
||||
{
|
||||
}
|
||||
public:
|
||||
virtual void ConvertToEbookPage(NSEBook::CFormat& oFormat)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GetPositionY()
|
||||
|
||||
CAtlList<ILogicItem*> arraySort;
|
||||
|
||||
while (0 != m_arItems.GetCount())
|
||||
{
|
||||
POSITION pos = m_arItems.GetHeadPosition();
|
||||
POSITION posNeed = pos;
|
||||
|
||||
ILogicItem* pItem = m_arItems.GetNext(pos);
|
||||
double dMin = pItem->GetPositionY();
|
||||
while (NULL != pos)
|
||||
{
|
||||
POSITION posOld = pos;
|
||||
pItem = m_arItems.GetNext(pos);
|
||||
|
||||
double dMem = pItem->GetPositionY();
|
||||
if (dMem < dMin)
|
||||
{
|
||||
dMin = dMem;
|
||||
posNeed = posOld;
|
||||
}
|
||||
}
|
||||
|
||||
ILogicItem* pNeed = m_arItems.GetAt(posNeed);
|
||||
m_arItems.RemoveAt(posNeed);
|
||||
arraySort.AddTail(pNeed);
|
||||
}
|
||||
m_arItems.RemoveAll();
|
||||
m_arItems.AddTailList(&arraySort);
|
||||
arraySort.RemoveAll();
|
||||
|
||||
CEbookParagraph* pLogicParagraph = NULL;
|
||||
|
||||
if (0 != oFormat.m_listSections.GetCount())
|
||||
{
|
||||
CSection& oSectionLast = oFormat.m_listSections.GetTail();
|
||||
IEbookItem* pItem = oSectionLast.m_arItems.GetTail();
|
||||
|
||||
if (NULL != pItem)
|
||||
{
|
||||
if (IEbookItem::ebitParagraph == pItem->m_eType)
|
||||
{
|
||||
pLogicParagraph = (CEbookParagraph*)pItem;
|
||||
|
||||
if (pLogicParagraph->m_bIsComplete)
|
||||
pLogicParagraph = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
POSITION pos = m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CSection* pSection = NULL;
|
||||
bool bIsFirstSection = true;
|
||||
if (0 == oFormat.m_listSections.GetCount())
|
||||
{
|
||||
oFormat.m_listSections.AddTail();
|
||||
pSection = &oFormat.m_listSections.GetTail();
|
||||
}
|
||||
else
|
||||
{
|
||||
pSection = &oFormat.m_listSections.GetTail();
|
||||
bIsFirstSection = false;
|
||||
}
|
||||
|
||||
ILogicItem* pItem = m_arItems.GetNext(pos);
|
||||
|
||||
if (ILogicItem::elitTextParagraph == pItem->m_eType)
|
||||
{
|
||||
CLogicParagraph* paragraph = dynamic_cast<CLogicParagraph*>(pItem);
|
||||
|
||||
if (paragraph->m_oParagraph.m_lStyle == 1 && !bIsFirstSection)
|
||||
{
|
||||
// <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> title. <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> - <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (1 < pSection->m_arItems.GetCount())
|
||||
{
|
||||
oFormat.m_listSections.AddTail();
|
||||
pSection = &oFormat.m_listSections.GetTail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case ILogicItem::elitTextParagraph:
|
||||
{
|
||||
CLogicParagraph* pCurrentPar = (CLogicParagraph*)pItem;
|
||||
if (NULL != pLogicParagraph)
|
||||
{
|
||||
// <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!!!
|
||||
pLogicParagraph->m_arLines.AddTailList(&pCurrentPar->m_oParagraph.m_arLines);
|
||||
pLogicParagraph->m_bIsComplete = pCurrentPar->m_oParagraph.m_bIsComplete;
|
||||
|
||||
pLogicParagraph->m_bIsPageBreakAfter = pItem->m_bIsPageBreakAfter;
|
||||
|
||||
pLogicParagraph = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
CEbookParagraph* pParagraph = new CEbookParagraph(pCurrentPar->m_oParagraph);
|
||||
pParagraph->m_bIsPageBreakAfter = pItem->m_bIsPageBreakAfter;
|
||||
pSection->m_arItems.AddTail(pParagraph);
|
||||
|
||||
CheckWatermark(oFormat);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ILogicItem::elitTable:
|
||||
{
|
||||
CEbookTable* pTable = new CEbookTable();
|
||||
pTable->m_strTableXml = ((CLogicTable*)pItem)->m_strTableXml;
|
||||
pSection->m_arItems.AddTail(pTable);
|
||||
|
||||
pTable->m_bIsPageBreakAfter = pItem->m_bIsPageBreakAfter;
|
||||
|
||||
CheckWatermark(oFormat);
|
||||
break;
|
||||
}
|
||||
case ILogicItem::elitGraphic:
|
||||
{
|
||||
CLogicImage* pLogicImage = ((CLogicImage*)pItem);
|
||||
|
||||
CEbookGraphicObject* pImage = new CEbookGraphicObject();
|
||||
pImage->m_oInfo = pLogicImage->m_oImageInfo;
|
||||
pImage->m_rcBounds = pItem->m_rcBounds;
|
||||
pSection->m_arItems.AddTail(pImage);
|
||||
|
||||
pImage->m_bIsPageBreakAfter = pItem->m_bIsPageBreakAfter;
|
||||
|
||||
CheckWatermark(oFormat);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void MoveTo(double& x, double& y)
|
||||
{
|
||||
m_oCurrentShape.MoveTo(x, y);
|
||||
}
|
||||
virtual void LineTo(double& x, double& y)
|
||||
{
|
||||
m_oCurrentShape.LineTo(x, y);
|
||||
}
|
||||
virtual void CurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
|
||||
{
|
||||
m_oCurrentShape.CurveTo(x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
virtual void Close()
|
||||
{
|
||||
m_oCurrentShape.Close();
|
||||
}
|
||||
virtual void BeginPath()
|
||||
{
|
||||
m_oCurrentShape.BeginPath();
|
||||
}
|
||||
virtual void EndPath()
|
||||
{
|
||||
m_oCurrentShape.EndPath();
|
||||
}
|
||||
|
||||
AVSINLINE void BeginParagraph()
|
||||
{
|
||||
if (m_bIsPar)
|
||||
return;
|
||||
|
||||
m_bIsPar = true;
|
||||
m_oText.m_oParagraph.m_rcBounds.top = 100000;
|
||||
m_oText.m_oParagraph.m_rcBounds.bottom = -100000;
|
||||
}
|
||||
AVSINLINE void EndParagraph()
|
||||
{
|
||||
if (100000 == m_oText.m_oParagraph.m_rcBounds.top)
|
||||
{
|
||||
if (100000 != m_dLastTop)
|
||||
{
|
||||
++m_dLastTop;
|
||||
m_oText.m_oParagraph.m_rcBounds.top = m_dLastTop;
|
||||
}
|
||||
}
|
||||
|
||||
if (100000 != m_oText.m_oParagraph.m_rcBounds.top)
|
||||
{
|
||||
CLogicParagraph* pPar = new CLogicParagraph(m_oText.m_oParagraph);
|
||||
pPar->m_rcBounds = m_oText.m_oParagraph.m_rcBounds;
|
||||
m_arItems.AddTail(pPar);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dLastTop = m_oText.m_oParagraph.m_rcBounds.top;
|
||||
}
|
||||
|
||||
m_oText.m_oParagraph.m_bIsComplete = true;
|
||||
m_oText.m_oParagraph.Clear();
|
||||
m_bIsPar = false;
|
||||
}
|
||||
AVSINLINE void BeginLine()
|
||||
{
|
||||
m_dCurrentBaselineOffset = 0;
|
||||
m_oText.m_oParagraph.m_arLines.AddTail();
|
||||
}
|
||||
AVSINLINE void EndLine()
|
||||
{
|
||||
}
|
||||
AVSINLINE void SetBaselineOffset(double dOffset)
|
||||
{
|
||||
m_dCurrentBaselineOffset = dOffset;
|
||||
}
|
||||
AVSINLINE void SetParagraphStyle(LONG lStyle)
|
||||
{
|
||||
m_oText.m_oParagraph.m_lStyle = lStyle;
|
||||
}
|
||||
AVSINLINE void SetParTextAlign(LONG lAlign)
|
||||
{
|
||||
m_oText.m_oParagraph.m_lTextAlign = lAlign;
|
||||
}
|
||||
AVSINLINE void SetParagraphNumLevel(LONG lLevel)
|
||||
{
|
||||
m_oText.m_oParagraph.m_lNumberingLevel = lLevel;
|
||||
}
|
||||
|
||||
virtual void WriteText(BSTR& bsText, BSTR& bsGid, double& x, double& y, double& width, double& height, double& baselineoffset)
|
||||
{
|
||||
if (0 != m_lShapeTop)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
m_oCurrentShape.WriteText(bsText, bsGid, x, y, width, height, baselineoffset, m_pFont, m_pBrush);
|
||||
return;
|
||||
}
|
||||
|
||||
m_oText.CommandText(bsText, bsGid, x, y, width, height, baselineoffset, m_dCurrentBaselineOffset);
|
||||
m_dCurrentBaselineOffset = 0.0;
|
||||
}
|
||||
|
||||
virtual void WriteTable(NSEBook::ILogicItem* pItem)
|
||||
{
|
||||
m_arItems.AddTail(pItem);
|
||||
}
|
||||
|
||||
AVSINLINE void WriteTableTop(double dTop)
|
||||
{
|
||||
ILogicItem* pItem = m_arItems.GetTail();
|
||||
if (NULL != pItem)
|
||||
{
|
||||
if (ILogicItem::elitTable == pItem->m_eType)
|
||||
pItem->m_rcBounds.top = dTop;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void BeginShape()
|
||||
{
|
||||
if (0 == m_lShapeTop)
|
||||
m_oCurrentShape.CreateShape(m_dWidth, m_dHeight);
|
||||
++m_lShapeTop;
|
||||
}
|
||||
virtual void EndShape()
|
||||
{
|
||||
--m_lShapeTop;
|
||||
if (0 == m_lShapeTop)
|
||||
{
|
||||
// <20><><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
m_oCurrentShape.GetShape((CBaseWriter*)this);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void DrawPath(LONG lType)
|
||||
{
|
||||
m_oCurrentShape.DrawPath(lType, m_pPen, m_pBrush);
|
||||
}
|
||||
virtual void Clear()
|
||||
{
|
||||
POSITION pos = m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
ILogicItem* pItem = m_arItems.GetNext(pos);
|
||||
RELEASEOBJECT(pItem);
|
||||
}
|
||||
m_arItems.RemoveAll();
|
||||
|
||||
m_oCurrentShape.Clear();
|
||||
m_lShapeTop = 0;
|
||||
}
|
||||
|
||||
virtual void BeginPage()
|
||||
{
|
||||
m_bIsPar = false;
|
||||
m_lShapeTop = 0;
|
||||
m_dCurrentBaselineOffset = 0;
|
||||
m_dLastTop = 100000;
|
||||
}
|
||||
virtual void EndPage()
|
||||
{
|
||||
if (m_bIsPar)
|
||||
{
|
||||
m_oText.m_oParagraph.m_bIsComplete = false;
|
||||
EndParagraph();
|
||||
}
|
||||
|
||||
m_bIsDumpWatermark = true;
|
||||
}
|
||||
virtual void CloseFile(NSEBook::CFormat& oFormat)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void WriteImage(IUnknown* punkImage, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
if (!m_bIsPar)
|
||||
{
|
||||
CLogicImage* pImage = new CLogicImage();
|
||||
pImage->m_oImageInfo = m_pImageManager->WriteImage(punkImage, x, y, width, height);
|
||||
pImage->m_rcBounds.left = x;
|
||||
pImage->m_rcBounds.top = y;
|
||||
pImage->m_rcBounds.right = x + width;
|
||||
pImage->m_rcBounds.bottom = y + height;
|
||||
m_arItems.AddTail(pImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
CEbookParagraph::CSpan oSpan;
|
||||
oSpan.m_oImageInfo = m_pImageManager->WriteImage(punkImage, x, y, width, height);
|
||||
oSpan.m_dImageWidth = width;
|
||||
oSpan.m_dImageHeight = height;
|
||||
|
||||
oSpan.m_dX = x;
|
||||
oSpan.m_dWidthSpan = width;
|
||||
|
||||
m_oText.m_oParagraph.m_rcBounds.top = min(m_oText.m_oParagraph.m_rcBounds.top, y);
|
||||
m_oText.m_oParagraph.m_rcBounds.bottom = max(m_oText.m_oParagraph.m_rcBounds.bottom, y);
|
||||
|
||||
CEbookParagraph::CLine& oCurLine = m_oText.GetCurrentLine();
|
||||
|
||||
if (0 == oCurLine.m_listSpans.GetCount())
|
||||
{
|
||||
oCurLine.m_listSpans.AddTail(oSpan);
|
||||
}
|
||||
else
|
||||
{
|
||||
CEbookParagraph::CSpan& oTail = oCurLine.m_listSpans.GetTail();
|
||||
if (-1 == oTail.m_oImageInfo.m_lID)
|
||||
{
|
||||
if (c_dSpaceW < FABS(oTail.m_dX + oTail.m_dWidthSpan - x))
|
||||
{
|
||||
oTail.m_oText.AddSpace();
|
||||
}
|
||||
}
|
||||
oCurLine.m_listSpans.AddTail(oSpan);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void WriteShape(IUnknown* punkImage, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
WriteImage(punkImage, x, y, width, height);
|
||||
}
|
||||
virtual void WriteImage(CString strFilePath, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
if (!m_bIsPar)
|
||||
{
|
||||
CLogicImage* pImage = new CLogicImage();
|
||||
pImage->m_oImageInfo = m_pImageManager->WriteImage(strFilePath, x, y, width, height);
|
||||
pImage->m_rcBounds.left = x;
|
||||
pImage->m_rcBounds.top = y;
|
||||
pImage->m_rcBounds.right = x + width;
|
||||
pImage->m_rcBounds.bottom = y + height;
|
||||
m_arItems.AddTail(pImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
CEbookParagraph::CSpan oSpan;
|
||||
oSpan.m_oImageInfo = m_pImageManager->WriteImage(strFilePath, x, y, width, height);
|
||||
oSpan.m_dImageWidth = width;
|
||||
oSpan.m_dImageHeight = height;
|
||||
|
||||
oSpan.m_dX = x;
|
||||
oSpan.m_dWidthSpan = width;
|
||||
|
||||
CEbookParagraph::CLine& oCurLine = m_oText.GetCurrentLine();
|
||||
|
||||
if (0 == oCurLine.m_listSpans.GetCount())
|
||||
{
|
||||
oCurLine.m_listSpans.AddTail(oSpan);
|
||||
}
|
||||
else
|
||||
{
|
||||
CEbookParagraph::CSpan& oTail = oCurLine.m_listSpans.GetTail();
|
||||
if (-1 == oTail.m_oImageInfo.m_lID)
|
||||
{
|
||||
if (c_dSpaceW < FABS(oTail.m_dX + oTail.m_dWidthSpan - x))
|
||||
{
|
||||
oTail.m_oText.AddSpace();
|
||||
}
|
||||
}
|
||||
oCurLine.m_listSpans.AddTail(oSpan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void InitProp()
|
||||
{
|
||||
m_oText.m_pFontsDst = &m_oFontsGen;
|
||||
m_oText.m_pFontManager = &m_oFontManager;
|
||||
m_oText.SetParams(m_pPen, m_pBrush, m_pFont, m_pTransform);
|
||||
m_oFontsGen.m_lCountFonts = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
BIN
AVSEBOOKWriter2/Logic/LogicPagePDF.h
Normal file
BIN
AVSEBOOKWriter2/Logic/LogicPagePDF.h
Normal file
Binary file not shown.
38
AVSEBOOKWriter2/Logic/Text.h
Normal file
38
AVSEBOOKWriter2/Logic/Text.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include "../Common/FontManager.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
using namespace NSCommon;
|
||||
|
||||
class ILogicItem
|
||||
{
|
||||
public:
|
||||
enum ELogicItemType
|
||||
{
|
||||
elitTextLine = 0,
|
||||
elitTable = 1,
|
||||
elitGraphic = 2,
|
||||
elitTextParagraph = 3
|
||||
};
|
||||
|
||||
ELogicItemType m_eType;
|
||||
CDoubleRect m_rcBounds;
|
||||
bool m_bIsPageBreakAfter;
|
||||
|
||||
public:
|
||||
ILogicItem()
|
||||
{
|
||||
m_eType = elitTextLine;
|
||||
m_bIsPageBreakAfter = false;
|
||||
}
|
||||
~ILogicItem()
|
||||
{
|
||||
}
|
||||
|
||||
virtual double GetPositionY() = 0;
|
||||
virtual double GetPositionX() = 0;
|
||||
};
|
||||
|
||||
const long g_lNewNoJustifySpace = 5;
|
||||
}
|
||||
250
AVSEBOOKWriter2/MOBIFormat/MobiFile.h
Normal file
250
AVSEBOOKWriter2/MOBIFormat/MobiFile.h
Normal file
@ -0,0 +1,250 @@
|
||||
#pragma once
|
||||
#include "MobiReader.h"
|
||||
#include "..\..\Common\OfficeFileTemplate.h"
|
||||
#include "..\..\AVSOfficeFile\OfficeEventsTemplate.h"
|
||||
#include "..\..\Common\OfficeFileFormats.h"
|
||||
#include "..\..\Common\OfficeFileErrorDescription.h"
|
||||
|
||||
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
|
||||
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
|
||||
#endif
|
||||
|
||||
template <class T, class Reciever>
|
||||
class COfficeHtmlEvent : public COfficeEventTemplate<T,Reciever>
|
||||
{
|
||||
public:
|
||||
COfficeHtmlEvent(Reciever *pReciever):COfficeEventTemplate(pReciever)
|
||||
{
|
||||
m_cnt = 0;
|
||||
m_dwAdvise = 0;
|
||||
};
|
||||
HRESULT OnProgress( LONG nID, LONG nPercent )
|
||||
{
|
||||
m_pReciever->OnProgress( nID, nPercent );
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT OnProgressEx( LONG nID, LONG nPercent, SHORT* Cancel )
|
||||
{
|
||||
m_pReciever->OnProgressEx( nID, nPercent, Cancel );
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
|
||||
VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
|
||||
{
|
||||
//CTemporaryCS oCS(&m_csThread);
|
||||
HRESULT hr;
|
||||
VARIANTARG varg0;
|
||||
VARIANTARG varg1;
|
||||
VARIANTARG varg2;
|
||||
switch(dispIdMember) {
|
||||
case 1:
|
||||
VariantInit(&varg0);
|
||||
VariantInit(&varg1);
|
||||
hr = DispGetParam(pDispParams,0,VT_I4,&varg0,puArgErr);
|
||||
hr = DispGetParam(pDispParams,1,VT_I4,&varg1,puArgErr);
|
||||
OnProgress( varg0.lVal, varg1.lVal );
|
||||
return(S_OK);
|
||||
break;
|
||||
case 2:
|
||||
VariantInit(&varg0);
|
||||
VariantInit(&varg1);
|
||||
VariantInit(&varg2);
|
||||
hr = DispGetParam(pDispParams,0,VT_I4,&varg0,puArgErr);
|
||||
hr = DispGetParam(pDispParams,1,VT_I4,&varg1,puArgErr);
|
||||
hr = DispGetParam(pDispParams,2,VT_I2,&varg2,puArgErr);
|
||||
OnProgressEx( varg0.lVal, varg1.lVal, &varg2.iVal );
|
||||
if (pDispParams->rgvarg[0].vt & VT_BYREF) // implemented now for last VT_I2 arg only
|
||||
{
|
||||
SHORT* p = (SHORT*)pDispParams->rgvarg[0].byref;
|
||||
if (p) *p = varg2.iVal;
|
||||
}
|
||||
return(S_OK);
|
||||
break;
|
||||
default:
|
||||
return(E_NOTIMPL);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// IOfficeMobiFile
|
||||
[
|
||||
object,
|
||||
uuid("A603595B-F537-4dbd-A616-4DFFF11613F0"),
|
||||
dual, helpstring("IOfficeMobiFile Interface"),
|
||||
pointer_default(unique)
|
||||
]
|
||||
__interface IOfficeMobiFile : IAVSOfficeFileTemplate
|
||||
{
|
||||
[id(10)] HRESULT SetAdditionalParam([in] BSTR ParamName, [in] VARIANT ParamValue);
|
||||
[id(20)] HRESULT GetAdditionalParam([in] BSTR ParamName, [out, retval] VARIANT* ParamValue);
|
||||
};
|
||||
|
||||
// COfficeMobiFile
|
||||
[
|
||||
coclass,
|
||||
default(IOfficeMobiFile),
|
||||
threading(apartment),
|
||||
event_source(com),
|
||||
vi_progid("Ebook.Mobi"),
|
||||
progid("Ebook.Mobi.1"),
|
||||
version(1.0),
|
||||
uuid("CB6B5C2C-9F3B-47d8-A184-187919722F88"),
|
||||
helpstring("COfficeMobiFile Class")
|
||||
]
|
||||
class ATL_NO_VTABLE COfficeMobiFile : public IOfficeMobiFile
|
||||
{
|
||||
public:
|
||||
COfficeMobiFile()
|
||||
{
|
||||
}
|
||||
__event __interface _IAVSOfficeFileTemplateEvents;
|
||||
__event __interface _IAVSOfficeFileTemplateEvents2;
|
||||
DECLARE_PROTECT_FINAL_CONSTRUCT()
|
||||
|
||||
HRESULT FinalConstruct()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void FinalRelease()
|
||||
{
|
||||
}
|
||||
public:
|
||||
STDMETHOD(LoadFromFile)( BSTR bstrSrcFileName, BSTR bstrDstPath, BSTR bstrXMLOptions)
|
||||
{
|
||||
CString strSrcFileName = (CString)bstrSrcFileName;
|
||||
if (!IsMobiFile(strSrcFileName))
|
||||
return S_FALSE;
|
||||
|
||||
NSMobi::CMobiReader oReader;
|
||||
oReader.m_oTempManager.m_strTempDirectory = _T("");
|
||||
oReader.m_bIsCorrectHtml = true;
|
||||
|
||||
m_strMetadata = _T("");
|
||||
bool bIsDRM = false;
|
||||
bool bIsMobi = oReader.OpenFile(strSrcFileName, bIsDRM);
|
||||
m_strMetadata = oReader.m_strMeta;
|
||||
|
||||
if (bIsDRM)
|
||||
{
|
||||
oReader.CloseFile();
|
||||
return AVS_ERROR_DRM;
|
||||
}
|
||||
|
||||
CString strHtmlFile = oReader.m_oTempManager.m_strTempDirectory + _T("\\index.html");
|
||||
CFile oFile;
|
||||
oFile.OpenFile(strHtmlFile);
|
||||
if (0 == oFile.GetFileSize())
|
||||
{
|
||||
oFile.CloseFile();
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
HRESULT hrRes = S_FALSE;
|
||||
if (bIsMobi)
|
||||
{
|
||||
OfficeHtmlFile::IHtmlFilePtr piHtmlFile;
|
||||
piHtmlFile.CreateInstance(__uuidof(OfficeHtmlFile::CHtmlFile));
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COfficeHtmlEvent< OfficeHtmlFile::_IAVSOfficeFileTemplateEvents, COfficeMobiFile >* oHtmlEvents = new COfficeHtmlEvent< OfficeHtmlFile::_IAVSOfficeFileTemplateEvents, COfficeMobiFile >( this );
|
||||
oHtmlEvents->AddRef();
|
||||
oHtmlEvents->Advise( piHtmlFile );
|
||||
COfficeHtmlEvent< OfficeHtmlFile::_IAVSOfficeFileTemplateEvents2, COfficeMobiFile >* oHtmlEvents2 = new COfficeHtmlEvent< OfficeHtmlFile::_IAVSOfficeFileTemplateEvents2, COfficeMobiFile >( this );
|
||||
oHtmlEvents2->AddRef();
|
||||
oHtmlEvents2->Advise( piHtmlFile );
|
||||
|
||||
BSTR bsSrc = strHtmlFile.AllocSysString();
|
||||
CString sOptions;
|
||||
sOptions.AppendFormat( _T("<Options><FileType>%d</FileType></Options>"), AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML );
|
||||
BSTR bstrOptions = sOptions.AllocSysString();
|
||||
hrRes = piHtmlFile->LoadFromFile(bsSrc, bstrDstPath, bstrOptions);
|
||||
SysFreeString(bsSrc);
|
||||
SysFreeString(bstrOptions);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
oHtmlEvents->UnAdvise( piHtmlFile );
|
||||
RELEASEINTERFACE( oHtmlEvents );
|
||||
oHtmlEvents2->UnAdvise( piHtmlFile );
|
||||
RELEASEINTERFACE( oHtmlEvents2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
OfficeTxtFile::ITxtFilePtr piHtmlFile;
|
||||
piHtmlFile.CreateInstance(__uuidof(OfficeTxtFile::CTxtFile));
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COfficeHtmlEvent< OfficeTxtFile::_IAVSOfficeFileTemplateEvents, COfficeMobiFile >* oHtmlEvents = new COfficeHtmlEvent< OfficeTxtFile::_IAVSOfficeFileTemplateEvents, COfficeMobiFile >( this );
|
||||
oHtmlEvents->AddRef();
|
||||
oHtmlEvents->Advise( piHtmlFile );
|
||||
COfficeHtmlEvent< OfficeTxtFile::_IAVSOfficeFileTemplateEvents2, COfficeMobiFile >* oHtmlEvents2 = new COfficeHtmlEvent< OfficeTxtFile::_IAVSOfficeFileTemplateEvents2, COfficeMobiFile >( this );
|
||||
oHtmlEvents2->AddRef();
|
||||
oHtmlEvents2->Advise( piHtmlFile );
|
||||
|
||||
strHtmlFile.Replace(_T("\\\\"), _T("\\"));
|
||||
BSTR bsSrc = strHtmlFile.AllocSysString();
|
||||
CString sOptions;
|
||||
sOptions.AppendFormat( _T("<Options><FileType>%d</FileType></Options>"), AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT );
|
||||
BSTR bstrOptions = sOptions.AllocSysString();
|
||||
hrRes = piHtmlFile->LoadFromFile(bsSrc, bstrDstPath, bstrOptions);
|
||||
SysFreeString(bsSrc);
|
||||
SysFreeString(bstrOptions);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
oHtmlEvents->UnAdvise( piHtmlFile );
|
||||
RELEASEINTERFACE( oHtmlEvents );
|
||||
oHtmlEvents2->UnAdvise( piHtmlFile );
|
||||
RELEASEINTERFACE( oHtmlEvents2 );
|
||||
}
|
||||
|
||||
oReader.CloseFile();
|
||||
|
||||
return hrRes;
|
||||
}
|
||||
STDMETHOD(SaveToFile)( BSTR bstrDstFileName, BSTR bstrSrcPath, BSTR bstrXMLOptions)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(SetAdditionalParam)( BSTR ParamName, VARIANT ParamValue)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(GetAdditionalParam)( BSTR ParamName, VARIANT* ParamValue)
|
||||
{
|
||||
CString sParamName = ParamName;
|
||||
if (_T("Metadata") == sParamName)
|
||||
{
|
||||
ParamValue->vt = VT_BSTR;
|
||||
ParamValue->bstrVal = m_strMetadata.AllocSysString();
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
BOOL IsMobiFile(CString sFilename)
|
||||
{
|
||||
CFile oFile;
|
||||
oFile.OpenFile(sFilename);
|
||||
if (70 > oFile.GetFileSize())
|
||||
return FALSE;
|
||||
|
||||
oFile.SetPosition(0);
|
||||
oFile.SkipBytes(60);
|
||||
|
||||
NSMobi::CStream oStream;
|
||||
oStream.CreateFromBuffer(10);
|
||||
oFile.ReadFile(oStream.GetBuffer(), 10);
|
||||
CString strId = oStream.ReadStringA(8);
|
||||
|
||||
BOOL bIsMobi = FALSE;
|
||||
if ((strId == _T("BOOKMOBI")) || (strId == _T("TEXtREAd")))
|
||||
bIsMobi = TRUE;
|
||||
|
||||
oFile.CloseFile();
|
||||
return bIsMobi;
|
||||
}
|
||||
private:
|
||||
|
||||
CString m_strMetadata;
|
||||
};
|
||||
1597
AVSEBOOKWriter2/MOBIFormat/MobiReader.h
Normal file
1597
AVSEBOOKWriter2/MOBIFormat/MobiReader.h
Normal file
File diff suppressed because it is too large
Load Diff
2772
AVSEBOOKWriter2/Objects.cpp
Normal file
2772
AVSEBOOKWriter2/Objects.cpp
Normal file
File diff suppressed because it is too large
Load Diff
978
AVSEBOOKWriter2/Objects.h
Normal file
978
AVSEBOOKWriter2/Objects.h
Normal file
@ -0,0 +1,978 @@
|
||||
#include "common/common.h"
|
||||
#include "writers/format.h"
|
||||
|
||||
using namespace NSEBook;
|
||||
class Page;
|
||||
|
||||
class Coordinates
|
||||
{
|
||||
protected:
|
||||
double m_x, m_y;
|
||||
public:
|
||||
Coordinates(): m_x(0), m_y(0) {}
|
||||
Coordinates(double x, double y): m_x(x), m_y(y) {}
|
||||
Coordinates(Coordinates &t_coord): m_x(t_coord.x()), m_y(t_coord.y()) {}
|
||||
~Coordinates() {}
|
||||
|
||||
virtual Coordinates operator=(Coordinates t_coord)
|
||||
{
|
||||
x(t_coord.x());
|
||||
y(t_coord.y());
|
||||
return *this;
|
||||
}
|
||||
virtual double x()
|
||||
{
|
||||
return m_x;
|
||||
}
|
||||
|
||||
virtual bool x(double t_x)
|
||||
{
|
||||
if(t_x > 0)
|
||||
{
|
||||
m_x = t_x;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual double y()
|
||||
{
|
||||
return m_y;
|
||||
}
|
||||
|
||||
virtual bool y(double t_y)
|
||||
{
|
||||
if(t_y > 0)
|
||||
{
|
||||
m_y = t_y;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class Size
|
||||
{
|
||||
protected:
|
||||
double m_width, m_height;
|
||||
public:
|
||||
Size():m_width(0),m_height(0){}
|
||||
Size(double width, double height):m_width(width),m_height(height){}
|
||||
Size(Size &t_size):m_width(t_size.width()),m_height(t_size.height()){}
|
||||
~Size(){}
|
||||
|
||||
virtual double width()
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
virtual bool width(double t_width)
|
||||
{
|
||||
if(t_width > 0)
|
||||
{
|
||||
m_width = t_width;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual double height()
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
virtual bool height(double t_height)
|
||||
{
|
||||
if(t_height > 0)
|
||||
{
|
||||
m_height = t_height;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool setSize(Size *t_size)
|
||||
{
|
||||
if(width(t_size->width()))
|
||||
if(height(t_size->height()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
virtual bool setSize(double t_width, double t_height)
|
||||
{
|
||||
if(width(t_width))
|
||||
if(height(t_height))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
virtual Size& operator=(Size &t_size)
|
||||
{
|
||||
setSize(&t_size);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename E>
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
virtual void next() = 0;
|
||||
virtual void prev() = 0;
|
||||
virtual E item() = 0;
|
||||
virtual void item(E item) = 0;
|
||||
virtual void first() = 0;
|
||||
virtual void last() = 0;
|
||||
virtual void goToID(long id) = 0;
|
||||
virtual long getID() = 0;
|
||||
virtual E popItem() = 0;
|
||||
};
|
||||
|
||||
template<typename E>
|
||||
class List
|
||||
{
|
||||
protected:
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
Node(){}
|
||||
Node(E p_obj): item(p_obj){}
|
||||
~Node(){}
|
||||
|
||||
Node *next;
|
||||
Node *prev;
|
||||
E item;
|
||||
};
|
||||
Node *head;
|
||||
//Node *current;
|
||||
long count;
|
||||
E pop(Node *p_node)
|
||||
{
|
||||
//E t_item;
|
||||
Node* tmp;
|
||||
if(p_node)
|
||||
{
|
||||
//current = p_node;
|
||||
p_node->next->prev = p_node->prev;
|
||||
p_node->prev->next = p_node->next;
|
||||
tmp = p_node;
|
||||
p_node = p_node->next;
|
||||
count--;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
return tmp->item;
|
||||
|
||||
}
|
||||
void sort(long position, long n)
|
||||
{
|
||||
E temp;
|
||||
Iterator<E> *p, *iter_forward = getIterator(position), *iter_back = getIterator(n);
|
||||
p = getIterator(n>>1);
|
||||
|
||||
do
|
||||
{
|
||||
while(iter_forward->item()->x() < p->item()->x() ) iter_forward->next();
|
||||
while(iter_back->item()->x() > p->item()->x() ) iter_back->prev();
|
||||
if (iter_forward->getID() <= iter_back->getID())
|
||||
{
|
||||
temp = iter_forward->item();
|
||||
iter_forward->item(iter_back->item());
|
||||
iter_back->item(temp);
|
||||
iter_forward->next();
|
||||
iter_back->prev();
|
||||
}
|
||||
} while (iter_forward->getID() <= iter_back->getID());
|
||||
if ( iter_back->getID() > 0 ) sort(0, iter_back->getID());
|
||||
if ( n > iter_forward->getID()) sort(position + iter_forward->getID(), n - iter_forward->getID());
|
||||
}
|
||||
|
||||
public:
|
||||
template<typename E>
|
||||
class ListIterator: public Iterator<E>
|
||||
{
|
||||
protected:
|
||||
List *parent;
|
||||
Node *currentNode;
|
||||
long index;
|
||||
|
||||
public:
|
||||
ListIterator(List *p_parent): parent(p_parent), index(0){}
|
||||
ListIterator(Node *p_node, long t_index, List *p_parent): currentNode(p_node), parent(p_parent), index(t_index){}
|
||||
~ListIterator(){parent = NULL; currentNode = NULL;}
|
||||
|
||||
void first()
|
||||
{
|
||||
currentNode = parent->head;
|
||||
index = 0;
|
||||
}
|
||||
|
||||
void last()
|
||||
{
|
||||
currentNode = parent->head->prev;
|
||||
index = parent->count - 1;
|
||||
}
|
||||
|
||||
void goToID(long t_index)
|
||||
{
|
||||
if(t_index < parent->count)
|
||||
{
|
||||
if(t_index == 0)
|
||||
first();
|
||||
else
|
||||
{
|
||||
if(t_index > 0 && index < t_index)
|
||||
{
|
||||
while(t_index > index)
|
||||
next();
|
||||
}
|
||||
if(t_index > 0 && index > t_index)
|
||||
{
|
||||
while(t_index < index)
|
||||
prev();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void next()
|
||||
{
|
||||
currentNode = currentNode->next;
|
||||
index++;
|
||||
}
|
||||
|
||||
void prev()
|
||||
{
|
||||
currentNode = currentNode->prev;
|
||||
index--;
|
||||
}
|
||||
|
||||
long getID()
|
||||
{
|
||||
if(parent->count)
|
||||
{
|
||||
if(index > parent->count)
|
||||
index = index % parent->count;
|
||||
if(index < 0)
|
||||
{
|
||||
index *= -1;
|
||||
index = index % parent->count;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
E item()
|
||||
{
|
||||
return currentNode->item;
|
||||
}
|
||||
|
||||
E popItem()
|
||||
{
|
||||
if(index != 0)
|
||||
{
|
||||
Node* tmp;
|
||||
currentNode->next->prev = currentNode->prev;
|
||||
currentNode->prev->next = currentNode->next;
|
||||
tmp = currentNode;
|
||||
currentNode = currentNode->next;
|
||||
parent->count--;
|
||||
return tmp->item;//parent->pop(currentNode);
|
||||
}
|
||||
else
|
||||
return parent->pop();
|
||||
}
|
||||
void item(E p_item)
|
||||
{
|
||||
currentNode->item = p_item;
|
||||
}
|
||||
};
|
||||
|
||||
List()
|
||||
{
|
||||
count = 0;
|
||||
head = new Node;
|
||||
//head->item = NULL;
|
||||
head->next = head;
|
||||
head->prev = head;
|
||||
}
|
||||
~List()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void insert(long position, E p_obj)
|
||||
{
|
||||
if(position >= 0 && position < count)
|
||||
{
|
||||
Node *tmp;
|
||||
tmp = head;
|
||||
while(position > 1)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
position--;
|
||||
}
|
||||
Node *p_node = new Node(p_obj);
|
||||
p_node->next = tmp->next;
|
||||
p_node->prev = tmp;
|
||||
tmp->next = p_node;
|
||||
p_node->next->prev = p_node;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
void push(E p_obj)
|
||||
{
|
||||
if(count > 0)
|
||||
{
|
||||
Node *tmp = new Node(p_obj);
|
||||
tmp->prev = head->prev;
|
||||
tmp->next = head;
|
||||
head->prev->next = tmp;
|
||||
head->prev = tmp;
|
||||
head = tmp;
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
head->item = p_obj;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
void pushBack(E p_obj)
|
||||
{
|
||||
if(count > 0)
|
||||
{
|
||||
Node *tmp = new Node(p_obj);
|
||||
tmp->prev = head->prev;
|
||||
tmp->next = head;
|
||||
head->prev->next = tmp;
|
||||
head->prev = tmp;
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
head->item = p_obj;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
E first()
|
||||
{
|
||||
return head->item;
|
||||
}
|
||||
|
||||
E last()
|
||||
{
|
||||
return head->prev->item;
|
||||
}
|
||||
|
||||
E pop()
|
||||
{
|
||||
Node *tmp;
|
||||
if(count > 0)
|
||||
{
|
||||
tmp = head;
|
||||
head->next->prev = head->prev;
|
||||
head->prev->next = head->next;
|
||||
head = head->next;
|
||||
count--;
|
||||
}
|
||||
else
|
||||
tmp = head;
|
||||
return tmp->item;
|
||||
}
|
||||
|
||||
E popAt(long index)
|
||||
{
|
||||
long t_index = index;
|
||||
Node *tmp;
|
||||
if(count > 0 && index >= 0 && index < count)
|
||||
{
|
||||
if(index == 0)
|
||||
{
|
||||
tmp = head;
|
||||
head->next->prev = head->prev;
|
||||
head->prev->next = head->next;
|
||||
head = head->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = head;
|
||||
while(index > 0)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
index--;
|
||||
}
|
||||
tmp->next->prev = tmp->prev;
|
||||
tmp->prev->next = tmp->next;
|
||||
}
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
count--;
|
||||
return tmp->item;
|
||||
}
|
||||
|
||||
E getAt(long index)
|
||||
{
|
||||
Node *tmp;
|
||||
if(count > 0 && index >= 0 && index < count)
|
||||
{
|
||||
tmp = head;
|
||||
while(index > 0)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
index--;
|
||||
}
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
return tmp->item;
|
||||
}
|
||||
|
||||
E operator[](long index)
|
||||
{
|
||||
return getAt(index);
|
||||
}
|
||||
|
||||
long getCount() const
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
void sort()
|
||||
{
|
||||
if(count > 1)
|
||||
sort(0, count);
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
if(count > 0)
|
||||
{
|
||||
head->prev->next = NULL;
|
||||
Node *tmp;
|
||||
tmp = head;
|
||||
while(tmp != NULL)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
//head->item = NULL;
|
||||
delete head;
|
||||
head = tmp;
|
||||
}
|
||||
count = 0;
|
||||
head = new Node;
|
||||
head->next = head;
|
||||
head->prev = head;
|
||||
//head->item = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<E>* getIterator(long index = 0)
|
||||
{
|
||||
Node *tmp = head;
|
||||
long t_index = index;
|
||||
if(count > 0 && index > 0 && index < count)
|
||||
{
|
||||
while(index > 0)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
index--;
|
||||
}
|
||||
}
|
||||
return new ListIterator<E>(tmp, t_index, this);
|
||||
}
|
||||
|
||||
void copy(List *list)
|
||||
{
|
||||
Iterator<E> *iter = list->getIterator();
|
||||
long t_count = count = list->getCount();
|
||||
clear();
|
||||
while(t_count > 0)
|
||||
{
|
||||
push(iter->item());
|
||||
iter->next();
|
||||
t_count--;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Object: public Size, public Coordinates
|
||||
{
|
||||
public:
|
||||
enum ObjectType{group, table, list, image, unknown};
|
||||
protected:
|
||||
ObjectType type;
|
||||
public:
|
||||
Object();
|
||||
~Object();
|
||||
|
||||
virtual ObjectType getType();
|
||||
virtual void merge(Object* p_obj){}
|
||||
virtual void resize(){}
|
||||
virtual Object* split(bool orient, double x, double y){return NULL;}
|
||||
|
||||
//virtual bool isDefaultStyle();
|
||||
//virtual bool setStyle(Style& s);
|
||||
//virtual Style* getStyle();
|
||||
//virtual int getType();
|
||||
virtual void coord(Coordinates& c);
|
||||
virtual Coordinates* coord();
|
||||
virtual void size(Size& s);
|
||||
virtual Size* size() const;
|
||||
};
|
||||
|
||||
class SymbolObject: public Object
|
||||
{
|
||||
public:
|
||||
enum ElementTypes{space, sign, word};
|
||||
protected:
|
||||
ElementTypes elementType;
|
||||
wchar_t m_code;
|
||||
wchar_t symbol;
|
||||
public:
|
||||
SymbolObject();
|
||||
SymbolObject(wchar_t *t_text, wchar_t *code):symbol(*t_text), m_code(*code){}
|
||||
~SymbolObject(){}
|
||||
virtual void setType(ElementTypes t_type);
|
||||
virtual ElementTypes getElementType();
|
||||
void code(wchar_t *code);
|
||||
wchar_t code();
|
||||
void setText(wchar_t *t_symbol);
|
||||
wchar_t getText() const;
|
||||
};
|
||||
|
||||
class Word: public SymbolObject, public List<SymbolObject*>
|
||||
{
|
||||
public:
|
||||
Word(){}
|
||||
~Word(){}
|
||||
};
|
||||
|
||||
class SymbolLine: public Object , public List<SymbolObject*>
|
||||
{
|
||||
protected:
|
||||
double m_baseLine;
|
||||
public:
|
||||
SymbolLine();
|
||||
SymbolLine(SymbolLine &line);
|
||||
~SymbolLine(){}
|
||||
|
||||
double baseLine();
|
||||
void baseLine(double t_baseLine);
|
||||
virtual void resize();
|
||||
virtual SymbolLine* split(double t_x);
|
||||
virtual SymbolLine* split(long position);
|
||||
};
|
||||
|
||||
class LineGroup: public Object, public List<SymbolLine*>
|
||||
{
|
||||
public:
|
||||
enum Align {right, left, middle, justify, unknown};
|
||||
protected:
|
||||
Align m_align;
|
||||
double commonVerticalSpace;
|
||||
public:
|
||||
bool flag;// it is worst design ever... bat I didnit have a choice
|
||||
LineGroup();
|
||||
~LineGroup();
|
||||
int align();
|
||||
void align(Align t_a);
|
||||
double space();
|
||||
void space(double t_x);
|
||||
virtual void resize();
|
||||
virtual LineGroup* split(bool orient, double x, double y);
|
||||
virtual void merge(LineGroup* p_group);
|
||||
};
|
||||
|
||||
class GroupList:public Object, public List<LineGroup*>
|
||||
{
|
||||
};
|
||||
|
||||
class Image: public Object
|
||||
{
|
||||
protected:
|
||||
CImageInfo info;
|
||||
public:
|
||||
Image(){ type = Object::image;}
|
||||
Image(CImageInfo p_info):info(p_info){ type = Object::image;}
|
||||
~Image(){}
|
||||
void setImageInfo(CImageInfo p_info);
|
||||
CImageInfo getImageInfo() const;
|
||||
};
|
||||
|
||||
class GraphicLine: public Object
|
||||
{
|
||||
protected:
|
||||
Coordinates m_endPoint;
|
||||
int m_orient; // 90 - vertical, 0 - horizontal
|
||||
public:
|
||||
GraphicLine(){}
|
||||
GraphicLine(Coordinates t_startPoint, Coordinates t_endPoint): m_endPoint(t_endPoint) {m_x = t_startPoint.x(); m_y = t_startPoint.y();}
|
||||
~GraphicLine(){}
|
||||
|
||||
void endPoint(Coordinates t_endPoint);
|
||||
Coordinates endPoint();
|
||||
void setOrientationHint(int orient);
|
||||
int orient(){return m_orient;}
|
||||
};
|
||||
|
||||
class Cell: public Object
|
||||
{
|
||||
protected:
|
||||
Object *m_content;// something...
|
||||
long m_rowID, m_columnID;
|
||||
bool borders[4];// visability of borders
|
||||
int mergeXcount, mergeYcount;
|
||||
public:
|
||||
Cell();
|
||||
Cell(long rowID, long columnID, Object* p_content = NULL);
|
||||
~Cell(){}
|
||||
|
||||
bool merged;
|
||||
void addCell(int, int);
|
||||
int cellCountX();
|
||||
int cellCountY();
|
||||
//virtual bool Merged();
|
||||
virtual void resize();
|
||||
long rowID();
|
||||
void rowID(long t_id);
|
||||
long columnID();
|
||||
void columnID(long t_id);
|
||||
Cell* split(bool orient, double& x, double& y);
|
||||
bool setBordersVisability(int number, bool visible);
|
||||
void content(Object *t_object);
|
||||
Object* content() const;
|
||||
};
|
||||
|
||||
class Table2: public Object
|
||||
{
|
||||
protected:
|
||||
List<List<Cell*>*> *rows;
|
||||
long m_columnCount;
|
||||
public:
|
||||
Table2();
|
||||
Table2(long rowCount, long columnCount);
|
||||
~Table2();
|
||||
|
||||
List<Cell*>* getRow(long id);
|
||||
Iterator<List<Cell*>*>* getRowIterator();
|
||||
void addRow();
|
||||
void pushRow(List<Cell*>* row);
|
||||
bool empty();
|
||||
long getCount();
|
||||
long columnCount();
|
||||
void columnCount(long);
|
||||
virtual void resize();
|
||||
};
|
||||
|
||||
class Parser// bad time... bad classes...
|
||||
{
|
||||
protected:
|
||||
|
||||
List<Page*> *pages;
|
||||
|
||||
List<Table2*> *graphicTables;
|
||||
List<Table2*> *textTables;
|
||||
List<GroupList*> *lists;
|
||||
List<GraphicLine*> *graphicLines;
|
||||
List<SymbolLine*> *symbolLines;
|
||||
List<LineGroup*> *groups;
|
||||
List<Image*> *images;
|
||||
|
||||
SymbolLine *currentLine;
|
||||
Word *currentWord;
|
||||
|
||||
bool thereAreSpaces;
|
||||
Coordinates coord;
|
||||
|
||||
BYTE *buffer;
|
||||
long pixelWidth;
|
||||
long pixelHeight;
|
||||
|
||||
double currentYcoord;
|
||||
double maxLineWidth;
|
||||
double minSymbolWidth;
|
||||
double maxSymbolWidth;
|
||||
double verticalLineSpace;
|
||||
struct Space
|
||||
{
|
||||
double space;
|
||||
long count;
|
||||
};
|
||||
|
||||
struct IntersectionPoint
|
||||
{
|
||||
GraphicLine *vertical, *horizontal;
|
||||
Coordinates coord;
|
||||
long columnId, rowId;
|
||||
};
|
||||
List<IntersectionPoint*> *points;
|
||||
struct PointMap
|
||||
{
|
||||
List<List<IntersectionPoint*>*> rowList;
|
||||
void addEmptyPoints()
|
||||
{
|
||||
long maxPointCount = 0;
|
||||
List<IntersectionPoint*> *rowExample;
|
||||
Iterator<List<IntersectionPoint*>*> *rowIterator = rowList.getIterator();
|
||||
while(rowIterator->getID() < rowList.getCount())
|
||||
{
|
||||
if(rowIterator->item()->getCount() > maxPointCount)
|
||||
{
|
||||
rowExample = rowIterator->item();
|
||||
maxPointCount = rowIterator->item()->getCount();
|
||||
}
|
||||
rowIterator->next();
|
||||
}
|
||||
Iterator<IntersectionPoint*> *examplePointIterator = rowExample->getIterator();
|
||||
rowIterator->first();
|
||||
while(rowIterator->getID() < rowList.getCount())
|
||||
{
|
||||
if(rowIterator->item()->getCount() < maxPointCount)
|
||||
{
|
||||
examplePointIterator->first();
|
||||
Iterator<IntersectionPoint*> *pointIterator = rowIterator->item()->getIterator();
|
||||
while(examplePointIterator->getID() < maxPointCount)
|
||||
{
|
||||
bool flag = true;
|
||||
pointIterator->first();
|
||||
while(flag && pointIterator->getID() < rowIterator->item()->getCount())
|
||||
{
|
||||
if(pointIterator->item()->coord.x() == examplePointIterator->item()->coord.x())
|
||||
flag = false;
|
||||
pointIterator->next();
|
||||
}
|
||||
if(flag)
|
||||
{
|
||||
//if(pointIterator->item()->coord.x() != examplePointIterator->item()->coord.x())
|
||||
//{
|
||||
pointIterator->prev();
|
||||
IntersectionPoint* point = new IntersectionPoint;
|
||||
point->coord.x(examplePointIterator->item()->coord.x());
|
||||
point->coord.y(pointIterator->item()->coord.y());
|
||||
if(pointIterator->item()->horizontal->x() < point->coord.x() && pointIterator->item()->horizontal->endPoint().x() > point->coord.x())
|
||||
{
|
||||
point->horizontal = pointIterator->item()->horizontal;
|
||||
}
|
||||
else
|
||||
{
|
||||
point->horizontal = NULL;
|
||||
}
|
||||
//----------------------------
|
||||
long id = rowIterator->getID();
|
||||
bool stop = false;
|
||||
while(!stop)
|
||||
{
|
||||
if(id == 0)
|
||||
{
|
||||
rowIterator->next();
|
||||
}
|
||||
else
|
||||
{
|
||||
rowIterator->prev();
|
||||
}
|
||||
Iterator<IntersectionPoint*> *aditionalPointIterator = rowIterator->item()->getIterator();
|
||||
while(!stop && aditionalPointIterator->getID() < rowIterator->item()->getCount())
|
||||
{
|
||||
if(aditionalPointIterator->item()->coord.x() == point->coord.x())
|
||||
{
|
||||
stop = true;
|
||||
if(aditionalPointIterator->item()->vertical->y() < point->coord.y() && aditionalPointIterator->item()->vertical->endPoint().y() > point->coord.y())
|
||||
point->vertical = aditionalPointIterator->item()->vertical;
|
||||
else
|
||||
point->vertical = NULL;
|
||||
}
|
||||
aditionalPointIterator->next();
|
||||
}
|
||||
}
|
||||
rowIterator->goToID(id);
|
||||
rowIterator->item()->push(point);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// pointIterator->next();
|
||||
}
|
||||
examplePointIterator->next();
|
||||
}
|
||||
}
|
||||
rowIterator->next();
|
||||
}
|
||||
}
|
||||
void sort()
|
||||
{
|
||||
sortRowList();
|
||||
}
|
||||
protected:
|
||||
void sortRowList()
|
||||
{
|
||||
Iterator<List<IntersectionPoint*>*> *iter1 = rowList.getIterator();
|
||||
Iterator<List<IntersectionPoint*>*> *iter2 = rowList.getIterator();
|
||||
iter2->next();
|
||||
while(iter1->getID() < rowList.getCount())
|
||||
{
|
||||
sortRow(iter1->item());
|
||||
iter1->next();
|
||||
}
|
||||
iter1->first();
|
||||
for(int i = 0; i < rowList.getCount(); i++)
|
||||
{
|
||||
while(iter2->getID() < rowList.getCount())
|
||||
{
|
||||
if(iter1->item()->first()->coord.y() > iter2->item()->first()->coord.y())
|
||||
{
|
||||
List<IntersectionPoint*> *row = iter1->item();
|
||||
iter1->item(iter2->item());
|
||||
iter2->item(row);
|
||||
}
|
||||
iter1->next();
|
||||
iter2->next();
|
||||
}
|
||||
iter1->first();
|
||||
iter2->first();
|
||||
iter2->next();
|
||||
}
|
||||
}
|
||||
/*void sortColumnList()
|
||||
{
|
||||
//List<List<IntersectionPoint*>*>::
|
||||
Iterator<List<IntersectionPoint*>*> *iter1 = columnList.getIterator();
|
||||
//List<List<IntersectionPoint*>*>::
|
||||
Iterator<List<IntersectionPoint*>*> *iter2 = columnList.getIterator();
|
||||
iter2->next();
|
||||
//while(iter1->getID() < columnList.getCount())
|
||||
//{
|
||||
// sortColumn(iter1->item());
|
||||
// iter1->next();
|
||||
//}
|
||||
iter1->first();
|
||||
for(int i = 0; i < columnList.getCount(); i++)
|
||||
{
|
||||
while(iter2->getID() < columnList.getCount())
|
||||
{
|
||||
if(iter1->item()->first()->coord.x() > iter2->item()->first()->coord.x())
|
||||
{
|
||||
List<IntersectionPoint*> *column = iter1->item();
|
||||
iter1->item(iter2->item());
|
||||
iter2->item(column);
|
||||
}
|
||||
iter1->next();
|
||||
iter2->next();
|
||||
}
|
||||
iter1->first();
|
||||
iter2->first();
|
||||
iter2->next();
|
||||
}
|
||||
}*/
|
||||
void sortRow(List<IntersectionPoint*>* row)
|
||||
{
|
||||
Iterator<IntersectionPoint*> *iter1 = row->getIterator();
|
||||
Iterator<IntersectionPoint*> *iter2 = row->getIterator();
|
||||
iter2->next();
|
||||
for(int i = 0; i < row->getCount(); i++)
|
||||
{
|
||||
while(iter2->getID() < row->getCount())
|
||||
{
|
||||
if(iter1->item()->coord.x() > iter2->item()->coord.x())
|
||||
{
|
||||
IntersectionPoint *point = iter1->item();
|
||||
iter1->item(iter2->item());
|
||||
iter2->item(point);
|
||||
iter1->item()->columnId = iter1->getID();
|
||||
iter2->item()->columnId = iter2->getID();
|
||||
}
|
||||
iter1->next();
|
||||
iter2->next();
|
||||
}
|
||||
iter1->first();
|
||||
iter2->first();
|
||||
iter2->next();
|
||||
}
|
||||
}
|
||||
|
||||
/*void sortColumn(List<IntersectionPoint*>* column)
|
||||
{
|
||||
//List<IntersectionPoint*>::
|
||||
Iterator<IntersectionPoint*> *iter1 = column->getIterator();
|
||||
//List<IntersectionPoint*>::
|
||||
Iterator<IntersectionPoint*> *iter2 = column->getIterator();
|
||||
iter2->next();
|
||||
for(int i = 0; i < column->getCount(); i++)
|
||||
{
|
||||
while(iter2->getID() < column->getCount())
|
||||
{
|
||||
if(iter1->item()->coord.y() > iter2->item()->coord.y())
|
||||
{
|
||||
IntersectionPoint *point = iter1->item();
|
||||
iter1->item(iter2->item());
|
||||
iter2->item(point);
|
||||
iter1->item()->rowId = iter1->getID();
|
||||
iter2->item()->rowId = iter2->getID();
|
||||
}
|
||||
iter1->next();
|
||||
iter2->next();
|
||||
}
|
||||
iter1->first();
|
||||
iter2->first();
|
||||
iter2->next();
|
||||
}
|
||||
}*/
|
||||
} *pointMap;
|
||||
|
||||
void createGraphicLines(long x, long y, long r, long b, bool &t);
|
||||
void findIntersections();
|
||||
void createPointMap();
|
||||
void createTable();
|
||||
void fillTables();
|
||||
bool findList(LineGroup* group, bool stage = false);
|
||||
void findGroup(SymbolLine *line);
|
||||
void findIntersectionPoint(GraphicLine *p_line1, GraphicLine *p_line2);
|
||||
bool findCell(Object* obj, Table2 *table);
|
||||
|
||||
|
||||
public:
|
||||
Parser():currentLine(new SymbolLine), symbolLines(new List<SymbolLine*>), currentWord(new Word),
|
||||
pointMap(new PointMap), pages(new List<Page*>), images(new List<Image*>),
|
||||
groups(new List<LineGroup*>), graphicLines(new List<GraphicLine*>), points(new List<IntersectionPoint*>), lists(new List<GroupList*>),
|
||||
graphicTables(new List<Table2*>), textTables(new List<Table2*>),
|
||||
maxLineWidth(0.0), minSymbolWidth(100.0), currentYcoord(0.0), verticalLineSpace(10.0), thereAreSpaces(false),
|
||||
maxSymbolWidth(0.0){currentWord->setType(SymbolObject::word);}//sheet happens
|
||||
|
||||
~Parser(){delete currentLine; delete images;
|
||||
delete pointMap; delete groups; delete currentWord;
|
||||
delete graphicLines; delete symbolLines; delete points;}
|
||||
|
||||
void clear();
|
||||
|
||||
virtual void lineTo(double& x, double& y);
|
||||
virtual void curve(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3){}
|
||||
virtual void moveTo(double& x, double& y);
|
||||
virtual void image(CImageInfo p_ibfo, double& x, double& y, double& width, double& height);
|
||||
virtual void text(BSTR& bsText, BSTR& bsGid, double& x, double& y, double& width, double& height, double& baselineoffset);
|
||||
virtual void beginPage();
|
||||
virtual void endPage();
|
||||
|
||||
Page* finishPage();
|
||||
|
||||
void setPixelBuffer(BYTE *buffer);
|
||||
void setPagePixelSize(long width, long height);
|
||||
bool analizeGraphic(long x, long y, long width, long height);
|
||||
|
||||
void toTXT();// for test only
|
||||
void toHTML();// for test only
|
||||
};
|
||||
|
||||
class Page
|
||||
{
|
||||
public:
|
||||
List<Object*> *items;
|
||||
|
||||
List<Table2*> *tables;
|
||||
List<GroupList*> *lists;
|
||||
List<LineGroup*> *groups;
|
||||
List<GraphicLine*> *lines;
|
||||
List<Image*> *images;
|
||||
|
||||
void createCommonList();
|
||||
};
|
||||
|
||||
355
AVSEBOOKWriter2/Writers/Format.h
Normal file
355
AVSEBOOKWriter2/Writers/Format.h
Normal file
@ -0,0 +1,355 @@
|
||||
#pragma once
|
||||
#include "../Common/FontManager.h"
|
||||
#include "../Logic/EbookPage.h"
|
||||
#include "TempManager.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
using namespace NSCommon;
|
||||
|
||||
class CMetadata
|
||||
{
|
||||
public:
|
||||
CString m_strAuthor;
|
||||
CString m_strName;
|
||||
CString m_strPublisher;
|
||||
CString m_strLanguage;
|
||||
|
||||
CString m_strCreatorProgram;
|
||||
|
||||
CString m_strCoverPath;
|
||||
|
||||
CAtlList<IEbookItem*> m_listAnnotation;
|
||||
|
||||
public:
|
||||
CMetadata() : m_listAnnotation()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
m_strAuthor = _T("");
|
||||
m_strName = _T("");
|
||||
m_strPublisher = _T("");
|
||||
m_strLanguage = _T("en");
|
||||
|
||||
m_strCreatorProgram = _T("Online Media Technologies Ltd.");
|
||||
|
||||
m_strCoverPath = _T("");
|
||||
|
||||
POSITION pos = m_listAnnotation.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = m_listAnnotation.GetNext(pos);
|
||||
RELEASEOBJECT(pItem);
|
||||
}
|
||||
m_listAnnotation.RemoveAll();
|
||||
}
|
||||
AVSINLINE void ClearNoAttack()
|
||||
{
|
||||
m_listAnnotation.RemoveAll();
|
||||
}
|
||||
|
||||
~CMetadata()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
CMetadata(const CMetadata& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CMetadata& operator=(const CMetadata& oSrc)
|
||||
{
|
||||
Clear();
|
||||
m_strAuthor = oSrc.m_strAuthor;
|
||||
m_strName = oSrc.m_strName;
|
||||
m_strPublisher = oSrc.m_strPublisher;
|
||||
m_strLanguage = oSrc.m_strLanguage;
|
||||
|
||||
m_strCreatorProgram = oSrc.m_strCreatorProgram;
|
||||
|
||||
m_strCoverPath = oSrc.m_strCoverPath;
|
||||
|
||||
m_listAnnotation.AddHeadList(&oSrc.m_listAnnotation);
|
||||
}
|
||||
};
|
||||
|
||||
class CSection
|
||||
{
|
||||
public:
|
||||
CAtlList<IEbookItem*> m_arTitle;
|
||||
CAtlList<IEbookItem*> m_arItems;
|
||||
|
||||
public:
|
||||
CSection() : m_arTitle(), m_arItems()
|
||||
{
|
||||
}
|
||||
~CSection()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
POSITION pos = m_arItems.GetHeadPosition();
|
||||
while (pos != NULL)
|
||||
{
|
||||
IEbookItem* pItem = m_arItems.GetNext(pos);
|
||||
RELEASEOBJECT(pItem);
|
||||
}
|
||||
m_arItems.RemoveAll();
|
||||
|
||||
pos = m_arTitle.GetHeadPosition();
|
||||
while (pos != NULL)
|
||||
{
|
||||
IEbookItem* pItem = m_arTitle.GetNext(pos);
|
||||
RELEASEOBJECT(pItem);
|
||||
}
|
||||
m_arTitle.RemoveAll();
|
||||
}
|
||||
|
||||
CSection(const CSection& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CSection& operator=(const CSection& oSrc)
|
||||
{
|
||||
Clear();
|
||||
|
||||
m_arItems.AddHeadList(&oSrc.m_arItems);
|
||||
m_arTitle.AddHeadList(&oSrc.m_arTitle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class CNotes
|
||||
{
|
||||
public:
|
||||
CAtlList<IEbookItem*> m_listItems;
|
||||
|
||||
public:
|
||||
CNotes() : m_listItems()
|
||||
{
|
||||
}
|
||||
~CNotes()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
POSITION pos = m_listItems.GetHeadPosition();
|
||||
while (pos != NULL)
|
||||
{
|
||||
IEbookItem* pItem = m_listItems.GetNext(pos);
|
||||
RELEASEOBJECT(pItem);
|
||||
}
|
||||
m_listItems.RemoveAll();
|
||||
}
|
||||
|
||||
CNotes(const CNotes& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CNotes& operator=(const CNotes& oSrc)
|
||||
{
|
||||
Clear();
|
||||
|
||||
m_listItems.AddHeadList(&oSrc.m_listItems);
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class CFormat
|
||||
{
|
||||
public:
|
||||
CMetadata m_oMeta;
|
||||
CAtlList<CSection> m_listSections;
|
||||
CNotes m_oNotes;
|
||||
|
||||
CTempManager m_oTempManager;
|
||||
CImageManager m_oImageManager;
|
||||
|
||||
public:
|
||||
CFormat() : m_oMeta(), m_oNotes(), m_listSections(), m_oTempManager(), m_oImageManager()
|
||||
{
|
||||
}
|
||||
~CFormat()
|
||||
{
|
||||
}
|
||||
|
||||
AVSINLINE void Clear()
|
||||
{
|
||||
m_listSections.RemoveAll();
|
||||
m_oNotes.Clear();
|
||||
|
||||
m_oImageManager.NewDocument();
|
||||
}
|
||||
|
||||
void ReadFromXml(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
Clear();
|
||||
|
||||
XmlUtils::CXmlNode oNodeMeta;
|
||||
if (oNode.GetNode(_T("metadata"), oNodeMeta))
|
||||
{
|
||||
m_oMeta.m_strAuthor = oNodeMeta.GetValue(_T("author"));
|
||||
m_oMeta.m_strName = oNodeMeta.GetValue(_T("name"));
|
||||
m_oMeta.m_strPublisher = oNodeMeta.GetValue(_T("publisher"));
|
||||
m_oMeta.m_strCreatorProgram = oNodeMeta.GetValue(_T("creator"));
|
||||
m_oMeta.m_strLanguage = oNodeMeta.GetValue(_T("language"));
|
||||
m_oMeta.m_strCoverPath = oNodeMeta.GetValue(_T("coverpath"));
|
||||
|
||||
XmlUtils::CXmlNode oNodeAnno;
|
||||
if (oNodeMeta.GetNode(_T("annotation"), oNodeAnno))
|
||||
{
|
||||
LoadElements(oNodeAnno, m_oMeta.m_listAnnotation);
|
||||
}
|
||||
}
|
||||
|
||||
XmlUtils::CXmlNodes oNodeSections;
|
||||
if (oNode.GetNodes(_T("sections"), oNodeSections))
|
||||
{
|
||||
int nCount = oNodeSections.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oNodeSection;
|
||||
oNodeSections.GetAt(0, oNodeSection);
|
||||
|
||||
CSection oSection;
|
||||
|
||||
XmlUtils::CXmlNode oTitle;
|
||||
if (oNodeSection.GetNode(_T("title"), oTitle))
|
||||
LoadElements(oTitle, oSection.m_arTitle);
|
||||
|
||||
XmlUtils::CXmlNode oElems;
|
||||
if (oNodeSection.GetNode(_T("items"), oElems))
|
||||
LoadElements(oElems, oSection.m_arItems);
|
||||
|
||||
m_listSections.AddTail(oSection);
|
||||
}
|
||||
}
|
||||
|
||||
XmlUtils::CXmlNode oNodeNotes;
|
||||
if (oNode.GetNode(_T("notes"), oNodeNotes))
|
||||
{
|
||||
LoadElements(oNodeNotes, m_oNotes.m_listItems);
|
||||
}
|
||||
}
|
||||
|
||||
CString SaveToXml()
|
||||
{
|
||||
CString strXml = _T("<ebook>");
|
||||
|
||||
// metadata
|
||||
strXml += (_T("<author>") + m_oMeta.m_strAuthor + _T("</author>"));
|
||||
strXml += (_T("<name>") + m_oMeta.m_strAuthor + _T("</name>"));
|
||||
strXml += (_T("<publisher>") + m_oMeta.m_strAuthor + _T("</publisher>"));
|
||||
strXml += (_T("<creator>") + m_oMeta.m_strAuthor + _T("</creator>"));
|
||||
strXml += (_T("<language>") + m_oMeta.m_strAuthor + _T("</language>"));
|
||||
strXml += (_T("<coverpath>") + m_oMeta.m_strAuthor + _T("</coverpath>"));
|
||||
|
||||
strXml += _T("<annotation>");
|
||||
POSITION pos = m_oMeta.m_listAnnotation.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = m_oMeta.m_listAnnotation.GetNext(pos);
|
||||
strXml += pItem->SaveToXml();
|
||||
}
|
||||
strXml += _T("</annotation>");
|
||||
|
||||
// items
|
||||
strXml += _T("<sections>");
|
||||
pos = m_listSections.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CSection& oSection = m_listSections.GetNext(pos);
|
||||
strXml += _T("<section><title>");
|
||||
|
||||
POSITION pos_ = oSection.m_arTitle.GetHeadPosition();
|
||||
while (NULL != pos_)
|
||||
{
|
||||
IEbookItem* pItem = oSection.m_arTitle.GetNext(pos_);
|
||||
strXml += pItem->SaveToXml();
|
||||
}
|
||||
|
||||
strXml += _T("</title><items>");
|
||||
|
||||
pos_ = oSection.m_arItems.GetHeadPosition();
|
||||
while (NULL != pos_)
|
||||
{
|
||||
IEbookItem* pItem = oSection.m_arItems.GetNext(pos_);
|
||||
strXml += pItem->SaveToXml();
|
||||
}
|
||||
|
||||
strXml += _T("</items></section>");
|
||||
}
|
||||
strXml += _T("</sections>");
|
||||
|
||||
// notes
|
||||
strXml += _T("<notes>");
|
||||
pos = m_oNotes.m_listItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = m_oNotes.m_listItems.GetNext(pos);
|
||||
pItem->SaveToXml();
|
||||
}
|
||||
strXml += _T("</notes>");
|
||||
|
||||
strXml += _T("</ebook>");
|
||||
return strXml;
|
||||
}
|
||||
|
||||
void LoadFromFile(CString strFile)
|
||||
{
|
||||
XmlUtils::CXmlNode oNode;
|
||||
if (oNode.FromXmlFile2(strFile))
|
||||
ReadFromXml(oNode);
|
||||
}
|
||||
void SaveToFile(CString strFile)
|
||||
{
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strFile);
|
||||
oFile.WriteStringUTF8(SaveToXml());
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
static IEbookItem* CreateElementFromNode(XmlUtils::CXmlNode& oNode)
|
||||
{
|
||||
CString strName = oNode.GetName();
|
||||
IEbookItem* pItem = NULL;
|
||||
if (_T("p") == strName)
|
||||
pItem = new CEbookParagraph();
|
||||
else if (_T("num") == strName)
|
||||
pItem = new CEbookNumbering();
|
||||
else if (_T("table") == strName)
|
||||
pItem = new CEbookTable();
|
||||
else if (_T("graphic") == strName)
|
||||
pItem = new CEbookGraphicObject();
|
||||
|
||||
if (NULL != pItem)
|
||||
pItem->ReadFromXml(oNode);
|
||||
|
||||
return pItem;
|
||||
}
|
||||
static void LoadElements(XmlUtils::CXmlNode& oNode, CAtlList<IEbookItem*>& oArray)
|
||||
{
|
||||
XmlUtils::CXmlNodes oNodes;
|
||||
if (oNode.GetNodes(_T("*"), oNodes))
|
||||
{
|
||||
int nCount = oNodes.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode node;
|
||||
oNodes.GetAt(i, node);
|
||||
IEbookItem* pItem = CreateElementFromNode(node);
|
||||
if (NULL != pItem)
|
||||
oArray.AddTail(pItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
87
AVSEBOOKWriter2/Writers/TempManager.h
Normal file
87
AVSEBOOKWriter2/Writers/TempManager.h
Normal file
@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
#include "../stdafx.h"
|
||||
#include <time.h>
|
||||
|
||||
namespace NSCommon
|
||||
{
|
||||
class CTempManager
|
||||
{
|
||||
public:
|
||||
CString m_strTempDirectory;
|
||||
CString m_strTempImagesDirectory;
|
||||
|
||||
public:
|
||||
CTempManager()
|
||||
{
|
||||
m_strTempDirectory = _T("");
|
||||
m_strTempImagesDirectory = _T("");
|
||||
}
|
||||
~CTempManager()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
void InitTempDirectory()
|
||||
{
|
||||
if (_T("") == m_strTempDirectory)
|
||||
{
|
||||
CStringW sTempPath;
|
||||
GetTempPathW(4096, sTempPath.GetBuffer(4096));
|
||||
sTempPath.ReleaseBuffer();
|
||||
|
||||
m_strTempDirectory = sTempPath;
|
||||
}
|
||||
|
||||
srand( (unsigned)time(NULL) );
|
||||
CString sNewDirName;
|
||||
do
|
||||
{
|
||||
int nRandom = rand() % 100000000;
|
||||
CString sRandName;
|
||||
sRandName.Format( _T("AVSEbookTemp%d"), nRandom );
|
||||
sNewDirName = m_strTempDirectory + _T("\\") + sRandName;
|
||||
}
|
||||
while( INVALID_FILE_ATTRIBUTES != ::GetFileAttributes( sNewDirName ) );
|
||||
|
||||
m_strTempDirectory = sNewDirName;
|
||||
m_strTempImagesDirectory = m_strTempDirectory + _T("\\media");
|
||||
|
||||
::CreateDirectory(m_strTempDirectory, NULL);
|
||||
::CreateDirectory(m_strTempImagesDirectory, NULL);
|
||||
}
|
||||
|
||||
void ZipDirectory(CString strDstFile)
|
||||
{
|
||||
AVSOfficeUtils::IOfficeUtils* pOfficeUtils = NULL;
|
||||
if (S_OK != CoCreateInstance(__uuidof(AVSOfficeUtils::COfficeUtils), NULL, CLSCTX_INPROC_SERVER, __uuidof(AVSOfficeUtils::IOfficeUtils),(void**)&pOfficeUtils))
|
||||
return;
|
||||
|
||||
BSTR bstrSrcPath = m_strTempDirectory.AllocSysString();
|
||||
BSTR bstrDstPath = strDstFile.AllocSysString();
|
||||
pOfficeUtils->CompressFileOrDirectory( bstrSrcPath, bstrDstPath, -1 );
|
||||
SysFreeString(bstrSrcPath);
|
||||
SysFreeString(bstrDstPath);
|
||||
RELEASEINTERFACE(pOfficeUtils);
|
||||
}
|
||||
|
||||
void RemoveTempDirectory()
|
||||
{
|
||||
if ( _T("") == m_strTempDirectory )
|
||||
return;
|
||||
|
||||
SHFILEOPSTRUCTW shfos;
|
||||
ZeroMemory(&shfos, sizeof(shfos));
|
||||
shfos.wFunc = FO_DELETE;
|
||||
CStringW _local = m_strTempDirectory + L"*.*";
|
||||
_local.AppendChar(0);
|
||||
_local.AppendChar(0);
|
||||
shfos.pFrom = _local.GetString();
|
||||
shfos.fFlags = FOF_SILENT + FOF_NOCONFIRMATION;
|
||||
|
||||
SHFileOperationW(&shfos);
|
||||
RemoveDirectory(m_strTempDirectory);
|
||||
|
||||
m_strTempDirectory = _T("");
|
||||
}
|
||||
};
|
||||
}
|
||||
275
AVSEBOOKWriter2/Writers/Writer.h
Normal file
275
AVSEBOOKWriter2/Writers/Writer.h
Normal file
@ -0,0 +1,275 @@
|
||||
#pragma once
|
||||
#include "Format.h"
|
||||
#include "../Logic/LogicPage.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CWriter
|
||||
{
|
||||
public:
|
||||
LONG m_lCurrentPageIndex;
|
||||
LONG m_lCountPages;
|
||||
|
||||
ILogicPage* m_pCurrentPage;
|
||||
CFormat m_oFormat;
|
||||
|
||||
CString m_strSrcFileName;
|
||||
|
||||
bool m_bIsSaveCover;
|
||||
bool m_bIsEmbeddedFonts;
|
||||
bool m_bIsSrcCoverExist;
|
||||
|
||||
AVSGraphics::IAVSEffectPainter* m_pPainter;
|
||||
public:
|
||||
CWriter()
|
||||
{
|
||||
m_pCurrentPage = NULL;
|
||||
m_pPainter = NULL;
|
||||
|
||||
m_lCurrentPageIndex = -1;
|
||||
m_lCountPages = 0;
|
||||
|
||||
m_strSrcFileName = _T("");
|
||||
|
||||
m_bIsSaveCover = true;
|
||||
m_bIsEmbeddedFonts = true;
|
||||
m_bIsSrcCoverExist = false;
|
||||
}
|
||||
~CWriter()
|
||||
{
|
||||
RELEASEINTERFACE(m_pPainter);
|
||||
}
|
||||
|
||||
CRenderers* CreateDocument(LONG lSrcType, LONG lDstType)
|
||||
{
|
||||
RELEASEOBJECT(m_pCurrentPage);
|
||||
m_oFormat.Clear();
|
||||
m_oFormat.m_oTempManager.InitTempDirectory();
|
||||
if (0 == lSrcType)
|
||||
{
|
||||
m_pCurrentPage = new CLogicPageDOCX();
|
||||
m_pCurrentPage->m_pImageManager = &m_oFormat.m_oImageManager;
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pCurrentPage = new CLogicPagePDF();
|
||||
CLogicPagePDF* pPagePDF = (CLogicPagePDF*)m_pCurrentPage;
|
||||
m_pCurrentPage->m_pImageManager = &m_oFormat.m_oImageManager;
|
||||
return &pPagePDF->m_oRenderers;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SetParametres(NSStructures::CPen* pPen, NSStructures::CBrush* pBrush, NSStructures::CFont* pFont,
|
||||
NSStructures::CShadow* pShadow, NSStructures::CEdgeText* pEdge,
|
||||
AVSGraphics::IAVSGraphicSimpleComverter* pSimpleConverter, NSCommon::CMatrix* pTransform)
|
||||
{
|
||||
m_pCurrentPage->m_pPen = pPen;
|
||||
m_pCurrentPage->m_pBrush = pBrush;
|
||||
m_pCurrentPage->m_pFont = pFont;
|
||||
m_pCurrentPage->m_pShadow = pShadow;
|
||||
m_pCurrentPage->m_pEdgeText = pEdge;
|
||||
|
||||
m_pCurrentPage->m_pSimpleGraphicsConverter = pSimpleConverter;
|
||||
m_pCurrentPage->m_pTransform = pTransform;
|
||||
|
||||
m_pCurrentPage->InitProp();
|
||||
|
||||
m_oFormat.m_oImageManager.m_strDstMedia = m_oFormat.m_oTempManager.m_strTempImagesDirectory;
|
||||
}
|
||||
|
||||
void CloseFile()
|
||||
{
|
||||
RELEASEOBJECT(m_pCurrentPage);
|
||||
m_oFormat.Clear();
|
||||
m_oFormat.m_oTempManager.RemoveTempDirectory();
|
||||
}
|
||||
void EndFile()
|
||||
{
|
||||
m_pCurrentPage->CloseFile(m_oFormat);
|
||||
}
|
||||
|
||||
void BeginPage(double dWidth, double dHeight)
|
||||
{
|
||||
++m_lCurrentPageIndex;
|
||||
if (0 != m_lCurrentPageIndex)
|
||||
m_pCurrentPage->Clear();
|
||||
|
||||
m_pCurrentPage->m_dWidth = dWidth;
|
||||
m_pCurrentPage->m_dHeight = dHeight;
|
||||
m_pCurrentPage->BeginPage();
|
||||
|
||||
m_pCurrentPage->m_pPen->SetDefaultParams();
|
||||
m_pCurrentPage->m_pBrush->SetDefaultParams();
|
||||
m_pCurrentPage->m_pFont->SetDefaultParams();
|
||||
}
|
||||
void EndPage()
|
||||
{
|
||||
m_pCurrentPage->EndPage();
|
||||
m_pCurrentPage->ConvertToEbookPage(m_oFormat);
|
||||
|
||||
m_pCurrentPage->Clear();
|
||||
}
|
||||
|
||||
public:
|
||||
AVSINLINE void MoveTo(double& x, double& y)
|
||||
{
|
||||
m_pCurrentPage->MoveTo(x, y);
|
||||
}
|
||||
AVSINLINE void LineTo(double& x, double& y)
|
||||
{
|
||||
m_pCurrentPage->LineTo(x, y);
|
||||
}
|
||||
AVSINLINE void CurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
|
||||
{
|
||||
m_pCurrentPage->CurveTo(x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
AVSINLINE void Close()
|
||||
{
|
||||
m_pCurrentPage->Close();
|
||||
}
|
||||
AVSINLINE void BeginPath()
|
||||
{
|
||||
m_pCurrentPage->BeginPath();
|
||||
}
|
||||
AVSINLINE void EndPath()
|
||||
{
|
||||
m_pCurrentPage->EndPath();
|
||||
}
|
||||
AVSINLINE void WriteText(BSTR bsText, BSTR bsGid, double& x, double& y, double& width, double& height, double& baselineoffset)
|
||||
{
|
||||
m_pCurrentPage->WriteText(bsText, bsGid, x, y, width, height, baselineoffset);
|
||||
}
|
||||
AVSINLINE void WriteImage(IUnknown* punkImage, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
size_t nCountImages = m_oFormat.m_oImageManager.m_listImages.GetCount();
|
||||
if (m_bIsSaveCover && (0 == nCountImages))
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
double _x = 0;
|
||||
double _y = 0;
|
||||
double _w = 210;
|
||||
double _h = 297;
|
||||
m_oFormat.m_oImageManager.WriteImage(punkImage, _x, _y, _w, _h);
|
||||
return;
|
||||
}
|
||||
else if ((0 == nCountImages) && m_bIsSrcCoverExist)
|
||||
{
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
return;
|
||||
}
|
||||
|
||||
m_pCurrentPage->WriteImage(punkImage, x, y, width, height);
|
||||
}
|
||||
AVSINLINE void WriteImage(CString strFilePath, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
size_t nCountImages = m_oFormat.m_oImageManager.m_listImages.GetCount();
|
||||
if (m_bIsSaveCover && (0 == nCountImages))
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
double _x = 0;
|
||||
double _y = 0;
|
||||
double _w = 210;
|
||||
double _h = 297;
|
||||
m_oFormat.m_oImageManager.WriteImage(strFilePath, _x, _y, _w, _h);
|
||||
return;
|
||||
}
|
||||
else if ((0 == nCountImages) && m_bIsSrcCoverExist)
|
||||
{
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
return;
|
||||
}
|
||||
|
||||
m_pCurrentPage->WriteImage(strFilePath, x, y, width, height);
|
||||
}
|
||||
AVSINLINE void WriteTable(NSEBook::ILogicItem* pItem)
|
||||
{
|
||||
m_pCurrentPage->WriteTable(pItem);
|
||||
}
|
||||
AVSINLINE void BeginShape()
|
||||
{
|
||||
m_pCurrentPage->BeginShape();
|
||||
}
|
||||
AVSINLINE void EndShape()
|
||||
{
|
||||
m_pCurrentPage->EndShape();
|
||||
}
|
||||
AVSINLINE void DrawPath(long nType)
|
||||
{
|
||||
m_pCurrentPage->DrawPath(nType);
|
||||
}
|
||||
|
||||
public:
|
||||
void InitWatermark()
|
||||
{
|
||||
if (NULL == m_pCurrentPage)
|
||||
return;
|
||||
|
||||
if (NULL == m_pPainter)
|
||||
{
|
||||
m_pCurrentPage->m_oInfoWatermark.m_lID = -1;
|
||||
m_pCurrentPage->m_oRectWatermark.left = 0;
|
||||
m_pCurrentPage->m_oRectWatermark.top = 0;
|
||||
m_pCurrentPage->m_oRectWatermark.right = 0;
|
||||
m_pCurrentPage->m_oRectWatermark.bottom = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LONG lWidthPix = 400;
|
||||
LONG lHeightPix = 75;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
CoCreateInstance(MediaCore::CLSID_CAVSUncompressedVideoFrame, NULL, CLSCTX_ALL,
|
||||
MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
pFrame->put_ColorSpace( ( 1 << 6) | ( 1 << 31) ); // CPS_BGRA | CPS_FLIP
|
||||
pFrame->put_Width( lWidthPix );
|
||||
pFrame->put_Height( lHeightPix );
|
||||
pFrame->put_AspectRatioX( lWidthPix );
|
||||
pFrame->put_AspectRatioY( lHeightPix );
|
||||
pFrame->put_Interlaced( VARIANT_FALSE );
|
||||
pFrame->put_Stride( 0, 4 * lWidthPix );
|
||||
pFrame->AllocateBuffer( -1 );
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
pFrame->get_Buffer(&pBuffer);
|
||||
memset(pBuffer, 0xFF, 4 * lWidthPix * lHeightPix);
|
||||
|
||||
AVSGraphics::IAVSGraphicsRenderer* pRenderer = NULL;
|
||||
CoCreateInstance(AVSGraphics::CLSID_CAVSGraphicsRenderer, NULL, CLSCTX_ALL,
|
||||
AVSGraphics::IID_IAVSGraphicsRenderer, (void**)&pRenderer);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FontManager
|
||||
VARIANT vtVariant;
|
||||
vtVariant.vt = VT_UNKNOWN;
|
||||
vtVariant.punkVal = NULL;
|
||||
pRenderer->SetAdditionalParam( L"FontManager", vtVariant );
|
||||
|
||||
IUnknown* punkWatermark = NULL;
|
||||
pFrame->QueryInterface(IID_IUnknown, (void**)&punkWatermark);
|
||||
|
||||
pRenderer->put_Width(140);
|
||||
pRenderer->put_Height(30);
|
||||
pRenderer->CreateFromMediaData(punkWatermark, 0, 0, lWidthPix, lHeightPix);
|
||||
|
||||
m_pPainter->Draw((IUnknown*)pRenderer);
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
RELEASEINTERFACE(pRenderer);
|
||||
|
||||
m_pCurrentPage->m_oRectWatermark.left = 0;
|
||||
m_pCurrentPage->m_oRectWatermark.top = 0;
|
||||
m_pCurrentPage->m_oRectWatermark.right = 140;
|
||||
m_pCurrentPage->m_oRectWatermark.bottom = 30;
|
||||
|
||||
double _x = 0;
|
||||
double _y = 0;
|
||||
double _w = 140;
|
||||
double _h = 30;
|
||||
|
||||
m_pCurrentPage->m_oInfoWatermark = m_oFormat.m_oImageManager.WriteImage(punkWatermark, _x, _y, _w, _h);
|
||||
}
|
||||
};
|
||||
}
|
||||
16
AVSEBOOKWriter2/Writers/Writer_Docx.h
Normal file
16
AVSEBOOKWriter2/Writers/Writer_Docx.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "Writer.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CWriter_Docx
|
||||
{
|
||||
public:
|
||||
void CreateDocument(CWriter* pWriter)
|
||||
{
|
||||
}
|
||||
void CloseFile(CString strDstFile, CWriter* pWriter)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
698
AVSEBOOKWriter2/Writers/Writer_Epub.h
Normal file
698
AVSEBOOKWriter2/Writers/Writer_Epub.h
Normal file
@ -0,0 +1,698 @@
|
||||
#pragma once
|
||||
#include "Writer.h"
|
||||
|
||||
#define CODEPAGE_ISSUE_FIX
|
||||
#include "../AVSOfficeUtils/ZLIB/zlib-1.2.3/contrib/minizip/zip.h"
|
||||
|
||||
#define BUFSIZE 2048
|
||||
#define MAXHTMLSIZE 1024*1024*50//130000 // 130000 bytes
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CWriter_Epub
|
||||
{
|
||||
private:
|
||||
NSCommon::CStringWriter m_oWriter;
|
||||
NSCommon::CStringWriter m_oWriterTOC;
|
||||
NSCommon::CStringWriter m_oWriterTOCReferenses;
|
||||
LONG m_lCurrentHtml;
|
||||
|
||||
CFormat* m_pFormat;
|
||||
LONG m_lSectionWrite;
|
||||
|
||||
CString m_strFontsItems;
|
||||
bool m_bIsFontsEmbedded;
|
||||
bool m_bIsSaveCover;
|
||||
|
||||
public:
|
||||
void CreateDocument(CWriter* pWriter)
|
||||
{
|
||||
m_bIsFontsEmbedded = pWriter->m_bIsEmbeddedFonts;
|
||||
m_bIsSaveCover = pWriter->m_bIsSaveCover;
|
||||
|
||||
m_lSectionWrite = 1;
|
||||
m_lCurrentHtml = 1;
|
||||
|
||||
// METAINF
|
||||
CString strMETA_INF = pWriter->m_oFormat.m_oTempManager.m_strTempDirectory + _T("\\META-INF");
|
||||
CDirectory::CreateDirectory(strMETA_INF);
|
||||
CString str1 = _T("<?xml version=\"1.0\"?><container version=\"1.0\" xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\">\
|
||||
<rootfiles><rootfile full-path=\"content.opf\" media-type=\"application/oebps-package+xml\"/></rootfiles></container>");
|
||||
CFile oFile1;
|
||||
oFile1.CreateFile(strMETA_INF + _T("\\container.xml"));
|
||||
oFile1.WriteStringUTF8(str1);
|
||||
oFile1.CloseFile();
|
||||
|
||||
// mimetype
|
||||
CStringA str2 = "application/epub+zip";
|
||||
CFile oFile2;
|
||||
oFile2.CreateFile(pWriter->m_oFormat.m_oTempManager.m_strTempDirectory + _T("\\mimetype"));
|
||||
oFile2.WriteFile((void*)str2.GetBuffer(), str2.GetLength());
|
||||
oFile2.CloseFile();
|
||||
|
||||
// css
|
||||
CString strCSS = _T(".heading1 { text-align: center; font-weight: bold; font-size: 2em; }\n\
|
||||
.heading2 { text-align: center; font-weight: bold; font-size: 1.5em; }n\
|
||||
.heading0 { text-indent: 2em; text-align: justify; font-size: 1em; }\n\
|
||||
.image_inline { vertical-align: baseline; }\n\
|
||||
.image_block { vertical-align: baseline; }\n\
|
||||
.bookpagebreak { display: block; page-break-after:always; margin-bottom: 0; margin-left: 0; margin-right: 0; margin-top: 0 }\n\
|
||||
p {text-indent: 1.5em; }\n\
|
||||
.main { display: block; font-size: 1em; margin-bottom: 0; margin-left: 5pt; margin-right: 5pt; margin-top: 0; padding-left: 0; padding-right: 0; text-align: justify }\n\
|
||||
.hyper { text-decoration: underline; }\n");
|
||||
|
||||
if (m_bIsFontsEmbedded && (NULL != pWriter->m_pCurrentPage))
|
||||
{
|
||||
::CreateDirectory(pWriter->m_oFormat.m_oTempManager.m_strTempDirectory + _T("\\fonts"), NULL);
|
||||
|
||||
CString strCssMem = _T("");
|
||||
m_strFontsItems = _T("");
|
||||
pWriter->m_pCurrentPage->m_oFontsGen.WriteFonts(pWriter->m_oFormat.m_oTempManager.m_strTempDirectory, strCssMem, m_strFontsItems);
|
||||
|
||||
strCSS += strCssMem;
|
||||
}
|
||||
|
||||
CFile oFile3;
|
||||
oFile3.CreateFile(pWriter->m_oFormat.m_oTempManager.m_strTempDirectory + _T("\\stylesheet.css"));
|
||||
oFile3.WriteStringUTF8(strCSS);
|
||||
oFile3.CloseFile();
|
||||
|
||||
m_pFormat = &pWriter->m_oFormat;
|
||||
POSITION posSect = m_pFormat->m_listSections.GetHeadPosition();
|
||||
while (NULL != posSect)
|
||||
{
|
||||
if (1 != m_lCurrentHtml)
|
||||
DumpCurrentHtml(m_pFormat);
|
||||
|
||||
CSection& oSection = m_pFormat->m_listSections.GetNext(posSect);
|
||||
DumpSection(&oSection);
|
||||
|
||||
POSITION pos = oSection.m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = oSection.m_arItems.GetNext(pos);
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case IEbookItem::ebitParagraph:
|
||||
{
|
||||
WriteParagraph((CEbookParagraph*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitTable:
|
||||
{
|
||||
WriteTable((CEbookTable*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitGraphic:
|
||||
{
|
||||
WriteImage((CEbookGraphicObject*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitNumbering:
|
||||
{
|
||||
WriteNumbering((CEbookNumbering*)pItem);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DumpCurrentHtml(m_pFormat, true);
|
||||
}
|
||||
void CloseFile(CString strDstFile, CWriter* pWriter)
|
||||
{
|
||||
WriteOPF(m_pFormat);
|
||||
CompressEpubDir(pWriter->m_oFormat.m_oTempManager.m_strTempDirectory, strDstFile);
|
||||
}
|
||||
|
||||
void DumpSection(CSection* pSection)
|
||||
{
|
||||
//DumpCurrentHtml(m_pFormat, true);
|
||||
if (m_oWriter.GetCurSize() > MAXHTMLSIZE)
|
||||
DumpCurrentHtml(m_pFormat, true);
|
||||
|
||||
CString strText = _T("");
|
||||
POSITION pos = pSection->m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = pSection->m_arItems.GetNext(pos);
|
||||
if (IEbookItem::ebitParagraph == pItem->m_eType)
|
||||
{
|
||||
CEbookParagraph* pParagraph = (CEbookParagraph*)pItem;
|
||||
strText = pParagraph->GetAllText();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CorrectString(strText);
|
||||
|
||||
GUID guid;
|
||||
CoCreateGuid(&guid);
|
||||
CString strGuid = _T("");
|
||||
strGuid.Format(_T("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"), guid.Data1, guid.Data2, guid.Data3,
|
||||
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
||||
|
||||
|
||||
CString s1 = _T("");
|
||||
s1.Format(_T("%d"), m_lSectionWrite++);
|
||||
CString s2 = _T("");
|
||||
s2.Format(_T("%d"), m_lCurrentHtml);
|
||||
|
||||
CString strSect = _T("<navPoint class=\"chapter\" id=\"") + strGuid + _T("\" playOrder=\"") + s1 + _T("\"><navLabel><text>") + strText +
|
||||
_T("</text></navLabel><content src=\"content_") + s2 + _T(".xhtml\"/></navPoint>");
|
||||
|
||||
m_oWriterTOC.WriteStringC(strSect);
|
||||
|
||||
CString strSectRef = _T("<p><a href=\"content_") + s2 + _T(".xhtml\"><span class=\"hyper\">") + strText + _T("</span></a></p>");
|
||||
m_oWriterTOCReferenses.WriteStringC(strSectRef);
|
||||
|
||||
}
|
||||
|
||||
void DumpCurrentHtml(NSEBook::CFormat* pFormat, bool bIsEnd = false)
|
||||
{
|
||||
if (bIsEnd)
|
||||
{
|
||||
if (0 == m_oWriter.GetCurSize())
|
||||
return;
|
||||
}
|
||||
|
||||
CString str1 = _T("<?xml version=\"1.0\" encoding=\"utf-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>") +
|
||||
pFormat->m_oMeta.m_strName + _T("</title><meta content=\"http://www.w3.org/1999/xhtml; charset=utf-8\" http-equiv=\"Content-Type\"/>\
|
||||
<link href=\"stylesheet.css\" type=\"text/css\" rel=\"stylesheet\"/><style type=\"text/css\"></style></head><body class=\"main\">");
|
||||
|
||||
CString str2 = _T("</body></html>");
|
||||
|
||||
CString strNum = _T("");
|
||||
|
||||
strNum.Format(_T("%d"), m_lCurrentHtml);
|
||||
|
||||
++m_lCurrentHtml;
|
||||
CString strSave = pFormat->m_oTempManager.m_strTempDirectory + _T("\\content_") + strNum + _T(".xhtml");
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strSave);
|
||||
BYTE utf8_mem[3];
|
||||
utf8_mem[0] = 0xEF;
|
||||
utf8_mem[1] = 0xBB;
|
||||
utf8_mem[2] = 0xBF;
|
||||
|
||||
oFile.WriteFile((void*)utf8_mem, 3);
|
||||
oFile.WriteStringUTF8(str1);
|
||||
|
||||
CString strBody = m_oWriter.GetCString();
|
||||
oFile.WriteStringUTF8(strBody);
|
||||
|
||||
oFile.WriteStringUTF8(str2);
|
||||
oFile.CloseFile();
|
||||
|
||||
m_oWriter.ClearNoAttack();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
static CStringA UnicodeToCodepage( CStringW sUni, UINT nCodepage = CP_UTF8 )
|
||||
{
|
||||
CStringA sUtf;
|
||||
int nBufSize = WideCharToMultiByte(nCodepage, 0, sUni, -1, NULL, NULL, NULL, NULL);
|
||||
LPSTR pBuff = new CHAR[ nBufSize + 1 ];
|
||||
WideCharToMultiByte(nCodepage, 0, sUni, -1, pBuff, nBufSize, NULL, NULL);
|
||||
pBuff[ nBufSize ] = 0;
|
||||
sUtf.Append( pBuff );
|
||||
delete pBuff;
|
||||
return sUtf;
|
||||
}
|
||||
|
||||
int _WriteFileToZip( CString sSource, CString sSourceRel, zipFile zf, int nCompressionLevel )
|
||||
{
|
||||
int err = 0;
|
||||
if( Z_NO_COMPRESSION == nCompressionLevel )
|
||||
err = zipOpenNewFileInZip( zf, UnicodeToCodepage (sSourceRel, CP_OEMCP), NULL, NULL, 0, NULL, 0, NULL, NULL, nCompressionLevel );
|
||||
else
|
||||
err = zipOpenNewFileInZip( zf, UnicodeToCodepage (sSourceRel, CP_OEMCP), NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, nCompressionLevel );
|
||||
HANDLE hSourceFile = ::CreateFile( sSource, GENERIC_READ, 0, 0, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if( INVALID_HANDLE_VALUE == hSourceFile )
|
||||
err = -1;
|
||||
DWORD dwBytesRead = 1;
|
||||
BYTE bBuffer[ BUFSIZE ];
|
||||
while( -1 != err && 0 != dwBytesRead )
|
||||
{
|
||||
ReadFile( hSourceFile, bBuffer, BUFSIZE, &dwBytesRead, NULL );
|
||||
if( dwBytesRead > 0 )
|
||||
err = zipWriteInFileInZip( zf, bBuffer, dwBytesRead );
|
||||
}
|
||||
RELEASEHANDLE( hSourceFile );
|
||||
if( 0 == err )
|
||||
err = zipCloseFileInZip( zf );
|
||||
else
|
||||
zipCloseFileInZip( zf );
|
||||
return err;
|
||||
}
|
||||
|
||||
int _CompressEpubDir( CString sSource, CString sPathRel, zipFile zf, int nCompresstionLevel )
|
||||
{
|
||||
DWORD dwFileAttrib = ::GetFileAttributes( sSource );
|
||||
if( dwFileAttrib != INVALID_FILE_ATTRIBUTES )
|
||||
{
|
||||
DWORD dwResult = 0;
|
||||
if( 0 != (FILE_ATTRIBUTE_DIRECTORY & dwFileAttrib) )
|
||||
{
|
||||
HANDLE Handle;
|
||||
WIN32_FIND_DATA FindData;
|
||||
DWORDLONG Result = 0;
|
||||
|
||||
Handle = FindFirstFile( ( sSource + _T("\\*.*") ), &FindData );
|
||||
if ( Handle == INVALID_HANDLE_VALUE )
|
||||
return 0;
|
||||
do
|
||||
{
|
||||
int nRes = 0;
|
||||
if( ( CString( FindData.cFileName ) != _T("mimetype") ) && ( CString( FindData.cFileName ) != _T(".") ) && ( CString( FindData.cFileName ) != _T("..") ) )
|
||||
{
|
||||
if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
|
||||
{
|
||||
if( _T("fonts") == CString( FindData.cFileName ) )
|
||||
dwResult += _CompressEpubDir( sSource + _T("\\") + FindData.cFileName, sPathRel + FindData.cFileName + _T("/"), zf, Z_NO_COMPRESSION );//<2F><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else
|
||||
dwResult += _CompressEpubDir( sSource + _T("\\") + FindData.cFileName, sPathRel + FindData.cFileName + _T("/"), zf, nCompresstionLevel );
|
||||
}
|
||||
else
|
||||
dwResult += _CompressEpubDir( sSource + _T("\\") + FindData.cFileName, sPathRel, zf, nCompresstionLevel );
|
||||
}
|
||||
}
|
||||
while( FindNextFile( Handle, &FindData ) != 0 );
|
||||
FindClose( Handle );
|
||||
}
|
||||
else
|
||||
{
|
||||
TCHAR tExt[256];
|
||||
TCHAR tFilename[256];
|
||||
_wsplitpath( sSource, NULL, NULL, tFilename, tExt );
|
||||
CString sExt = tExt;
|
||||
CString sFilename = tFilename;
|
||||
|
||||
_WriteFileToZip( sSource, sPathRel + sFilename + sExt, zf, nCompresstionLevel );
|
||||
}
|
||||
|
||||
return dwResult;
|
||||
}// 0 - <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
return 0;
|
||||
}
|
||||
int CompressEpubDir( CString sSource, CString sDestination )
|
||||
{
|
||||
int err = 0;
|
||||
zipFile zf = zipOpen( sDestination, APPEND_STATUS_CREATE );
|
||||
if( NULL == zf )
|
||||
return 1;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> mimetype
|
||||
CString sMimeFile = sSource + _T("\\mimetype");
|
||||
if( ::GetFileAttributes( sMimeFile ) != INVALID_FILE_ATTRIBUTES )
|
||||
err = _WriteFileToZip( sMimeFile, _T("mimetype"), zf, Z_NO_COMPRESSION );
|
||||
|
||||
if( err == 0 )
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
err = _CompressEpubDir( sSource, _T(""), zf, Z_BEST_COMPRESSION );
|
||||
}
|
||||
if( 0 == err )
|
||||
err = zipClose( zf, NULL );
|
||||
else
|
||||
zipClose( zf, NULL );
|
||||
return err;
|
||||
}
|
||||
|
||||
void WriteOPF(NSEBook::CFormat* pFormat)
|
||||
{
|
||||
NSCommon::CStringWriter oOpf;
|
||||
oOpf.WriteStringC(_T("<?xml version='1.0' encoding='utf-8'?><package xmlns=\"http://www.idpf.org/2007/opf\" version=\"2.0\"\
|
||||
unique-identifier=\"bookid\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:opf=\"http://www.idpf.org/2007/opf\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
|
||||
xmlns:dcterms=\"http://purl.org/dc/terms/\"><metadata>"));
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:publisher>"));
|
||||
oOpf.WriteStringC(CorrectString2(pFormat->m_oMeta.m_strPublisher));
|
||||
oOpf.WriteStringC(_T("</dc:publisher>"));
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:language>"));
|
||||
//oOpf.WriteStringC(CorrectString2(pFormat->m_oMeta.m_strLanguage));
|
||||
oOpf.WriteStringC(_T("</dc:language>"));
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:creator>"));
|
||||
oOpf.WriteStringC(CorrectString2(pFormat->m_oMeta.m_strAuthor));
|
||||
oOpf.WriteStringC(_T("</dc:creator>"));
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:title>"));
|
||||
oOpf.WriteStringC(CorrectString2(pFormat->m_oMeta.m_strName));
|
||||
oOpf.WriteStringC(_T("</dc:title>"));
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:contributor>"));
|
||||
oOpf.WriteStringC(CorrectString2(pFormat->m_oMeta.m_strCreatorProgram));
|
||||
oOpf.WriteStringC(_T("</dc:contributor>"));
|
||||
|
||||
if (0 != pFormat->m_oMeta.m_listAnnotation.GetCount())
|
||||
{
|
||||
oOpf.WriteStringC(_T("<dc:description>"));
|
||||
|
||||
POSITION pos = pFormat->m_oMeta.m_listAnnotation.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = pFormat->m_oMeta.m_listAnnotation.GetNext(pos);
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case IEbookItem::ebitParagraph:
|
||||
{
|
||||
CEbookParagraph* pPar = (CEbookParagraph*)pItem;
|
||||
oOpf.WriteStringC(CorrectString2(pPar->GetAllText()));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
oOpf.WriteStringC(_T("</dc:description>"));
|
||||
}
|
||||
|
||||
GUID guid;
|
||||
CoCreateGuid(&guid);
|
||||
CString strGuid = _T("");
|
||||
strGuid.Format(_T("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"), guid.Data1, guid.Data2, guid.Data3,
|
||||
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
||||
|
||||
oOpf.WriteStringC(_T("<dc:identifier id=\"bookid\" opf:scheme=\"uuid\">"));
|
||||
oOpf.WriteStringC(strGuid);
|
||||
oOpf.WriteStringC(_T("</dc:identifier>"));
|
||||
|
||||
if (m_bIsSaveCover)
|
||||
{
|
||||
LONG _lStartImage = max(m_lCurrentHtml, 1000);
|
||||
CString strCover = _T("");
|
||||
strCover.Format(_T("id%d"), _lStartImage);
|
||||
m_oWriter.WriteString(_T("<meta name=\"cover\" content=\"") + strCover + _T("\"/>"));
|
||||
}
|
||||
|
||||
oOpf.WriteStringC(_T("</metadata><manifest><opf:item id=\"ncx\" href=\"toc.ncx\" media-type=\"application/x-dtbncx+xml\"/>\
|
||||
<item href=\"book_toc.xhtml\" id=\"book_toc_id\" media-type=\"application/xhtml+xml\"/>\
|
||||
<item href=\"stylesheet.css\" id=\"css\" media-type=\"text/css\"/>"));
|
||||
|
||||
if (m_bIsSaveCover)
|
||||
{
|
||||
oOpf.WriteStringC(_T("<item id=\"cover\" href=\"cover.xhtml\" media-type=\"application/xhtml+xml\"/>"));
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> xhtml
|
||||
CFile oFileCover;
|
||||
oFileCover.CreateFile(pFormat->m_oTempManager.m_strTempDirectory + _T("\\cover.xhtml"));
|
||||
BYTE utf8_mem[3];
|
||||
utf8_mem[0] = 0xEF;
|
||||
utf8_mem[1] = 0xBB;
|
||||
utf8_mem[2] = 0xBF;
|
||||
|
||||
bool bIsPNG = false;
|
||||
if (0 != pFormat->m_oImageManager.m_listImages.GetCount())
|
||||
{
|
||||
if (NSCommon::itPNG == pFormat->m_oImageManager.m_listImages.GetHead().m_eType)
|
||||
bIsPNG = true;
|
||||
}
|
||||
|
||||
oFileCover.WriteFile((void*)utf8_mem, 3);
|
||||
|
||||
if (!bIsPNG)
|
||||
{
|
||||
CString strCoverXHTML = _T("<?xml version=\"1.0\" encoding=\"utf-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\">\
|
||||
<head><title>Cover</title></head><body><div class=\"coverpage\">\
|
||||
<img style=\"width:100%;height: 100%;\" alt=\"Cover\" src=\"media/image1.jpg\"/></div></body></html>");
|
||||
|
||||
oFileCover.WriteStringUTF8(strCoverXHTML);
|
||||
}
|
||||
else
|
||||
{
|
||||
CString strCoverXHTML = _T("<?xml version=\"1.0\" encoding=\"utf-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\">\
|
||||
<head><title>Cover</title></head><body><div class=\"coverpage\">\
|
||||
<img style=\"width:100%;height: 100%;\" alt=\"Cover\" src=\"media/image1.png\"/></div></body></html>");
|
||||
|
||||
oFileCover.WriteStringUTF8(strCoverXHTML);
|
||||
}
|
||||
oFileCover.CloseFile();
|
||||
}
|
||||
|
||||
for (LONG lStartText = 1; lStartText < m_lCurrentHtml; ++lStartText)
|
||||
{
|
||||
CString strText = _T("");
|
||||
strText.Format(_T("<item href=\"content_%d.xhtml\" id=\"id%d\" media-type=\"application/xhtml+xml\"/>"), lStartText, lStartText);
|
||||
oOpf.WriteStringC(strText);
|
||||
}
|
||||
|
||||
LONG lStartImage = max(m_lCurrentHtml, 1000);
|
||||
POSITION posImage = pFormat->m_oImageManager.m_listImages.GetHeadPosition();
|
||||
while (NULL != posImage)
|
||||
{
|
||||
CImageInfo& info = pFormat->m_oImageManager.m_listImages.GetNext(posImage);
|
||||
|
||||
if (itJPG == info.m_eType)
|
||||
{
|
||||
CString strText = _T("");
|
||||
strText.Format(_T("<item href=\"media/image%d.jpg\" id=\"id%d\" media-type=\"image/jpeg\"/>"), info.m_lID, lStartImage);
|
||||
oOpf.WriteStringC(strText);
|
||||
}
|
||||
else
|
||||
{
|
||||
CString strText = _T("");
|
||||
strText.Format(_T("<item href=\"media/%d.png\" id=\"id%d\" media-type=\"image/png\"/>"), info.m_lID, lStartImage);
|
||||
oOpf.WriteStringC(strText);
|
||||
}
|
||||
++lStartImage;
|
||||
}
|
||||
|
||||
oOpf.WriteStringC(m_strFontsItems);
|
||||
|
||||
oOpf.WriteStringC(_T("</manifest><spine toc=\"ncx\">"));
|
||||
|
||||
if (m_bIsSaveCover)
|
||||
{
|
||||
oOpf.WriteStringC(_T("<itemref idref=\"cover\"/>"));
|
||||
}
|
||||
|
||||
for (LONG i = 1; i < m_lCurrentHtml; ++i)
|
||||
{
|
||||
CString strText = _T("");
|
||||
strText.Format(_T("<itemref idref=\"id%d\"/>"), i);
|
||||
oOpf.WriteStringC(strText);
|
||||
}
|
||||
if (FALSE)
|
||||
{
|
||||
oOpf.WriteStringC(_T("<itemref idref=\"book_toc_id\"/>"));
|
||||
}
|
||||
|
||||
oOpf.WriteStringC(_T("</spine><guide><reference href=\"book_toc.xhtml#maintoc\" type=\"toc\" title=\"Table of Contents\"/></guide></package>"));
|
||||
|
||||
CFile oFile;
|
||||
oFile.CreateFile(pFormat->m_oTempManager.m_strTempDirectory + _T("\\content.opf"));
|
||||
CString strCont = oOpf.GetCString();
|
||||
oFile.WriteStringUTF8(strCont);
|
||||
oFile.CloseFile();
|
||||
|
||||
// toc.ncx
|
||||
CFile oFileTOC;
|
||||
oFileTOC.CreateFile(pFormat->m_oTempManager.m_strTempDirectory + _T("\\toc.ncx"));
|
||||
|
||||
CString str1 = _T("<?xml version=\"1.0\" encoding=\"utf-8\"?><ncx version=\"2005-1\" xmlns=\"http://www.daisy.org/z3986/2005/ncx/\">\
|
||||
<head><meta name=\"dtb:uid\" content=\"") + strGuid + _T("\"/><meta name=\"dtb:depth\" content=\"2\"/>\
|
||||
<meta content=\"Online Media Technologies Ltd.\" name=\"dtb:generator\"/><meta content=\"0\" name=\"dtb:totalPageCount\"/>\
|
||||
<meta content=\"0\" name=\"dtb:maxPageNumber\"/></head>\
|
||||
<docTitle><text>") + pFormat->m_oMeta.m_strName + _T("</text></docTitle><docAuthor><text>") + pFormat->m_oMeta.m_strAuthor + _T("</text></docAuthor><navMap>");
|
||||
oFileTOC.WriteStringUTF8(str1);
|
||||
m_oWriterTOC.WriteStringC(_T("</navMap></ncx>"));
|
||||
|
||||
CString str2 = m_oWriterTOC.GetCString();
|
||||
oFileTOC.WriteStringUTF8(str2);
|
||||
oFileTOC.CloseFile();
|
||||
|
||||
CFile oFileBook_toc;
|
||||
oFileBook_toc.CreateFile(pFormat->m_oTempManager.m_strTempDirectory + _T("\\book_toc.xhtml"));
|
||||
|
||||
CString str11 = _T("<?xml version='1.0' encoding='utf-8'?><html xmlns=\"http://www.w3.org/1999/xhtml\"><head>\
|
||||
<title>Table of Content</title><meta content=\"http://www.w3.org/1999/xhtml; charset=utf-8\" http-equiv=\"Content-Type\"/>\
|
||||
<link href=\"stylesheet.css\" type=\"text/css\" rel=\"stylesheet\"/><style type=\"text/css\"></style></head>\
|
||||
<body class=\"main\"><div id=\"maintoc\"><p class=\"heading1\"><span>Table of Contents</span></p>");
|
||||
|
||||
oFileBook_toc.WriteStringUTF8(str11);
|
||||
m_oWriterTOCReferenses.WriteStringC(_T("</div></body></html>"));
|
||||
|
||||
CString str22 = m_oWriterTOCReferenses.GetCString();
|
||||
oFileBook_toc.WriteStringUTF8(str22);
|
||||
oFileBook_toc.CloseFile();
|
||||
}
|
||||
|
||||
AVSINLINE void CheckSplitHtml()
|
||||
{
|
||||
if (m_oWriter.GetCurSize() > MAXHTMLSIZE)
|
||||
DumpCurrentHtml(m_pFormat);
|
||||
}
|
||||
|
||||
AVSINLINE void WriteImage(NSEBook::CEbookGraphicObject* pImage)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<div style=\"text-align:center;\"><img class=\"image_block\" src=\"media/image%d.%s\" alt=\"\"/></div>"), pImage->m_oInfo.m_lID,
|
||||
(NSCommon::itJPG == pImage->m_oInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
|
||||
if (pImage->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<div class=\"bookpagebreak\"/>"));
|
||||
}
|
||||
|
||||
CheckSplitHtml();
|
||||
}
|
||||
AVSINLINE void WriteParagraph(NSEBook::CEbookParagraph* pParagraph)
|
||||
{
|
||||
if (1 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading1\">"));
|
||||
else if (2 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading2\">"));
|
||||
else
|
||||
{
|
||||
if (0 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\">"));
|
||||
}
|
||||
else if (1 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\" style=\"text-align:center;\">"));
|
||||
}
|
||||
else if (2 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\" style=\"text-align:right;\">"));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\">"));
|
||||
}
|
||||
}
|
||||
|
||||
NSEBook::CEbookParagraph::CSpan* pSpan = NULL;
|
||||
|
||||
POSITION posLine = pParagraph->m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CLine& oLine = pParagraph->m_arLines.GetNext(posLine);
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (NULL == pSpan)
|
||||
pSpan = &oSpan;
|
||||
else if (pSpan->m_oFont.IsEqual(&oSpan.m_oFont) && pSpan->m_oBrush.IsEqual(&oSpan.m_oBrush)
|
||||
&& (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
pSpan->m_oText += oSpan.m_oText;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
pSpan = &oSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != pSpan)
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</p>"));
|
||||
|
||||
if (pParagraph->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<div class=\"bookpagebreak\"></div>"));
|
||||
//m_oWriter.WriteStringC(_T("<p style=\"page-break-after:always\"/>"));
|
||||
}
|
||||
|
||||
CheckSplitHtml();
|
||||
}
|
||||
|
||||
AVSINLINE void WriteSpan(NSEBook::CEbookParagraph::CSpan* pSpan)
|
||||
{
|
||||
if (-1 != pSpan->m_oImageInfo.m_lID)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<img class=\"image_inline\" src=\"media/image%d.%s\" alt=\"\"/>"), pSpan->m_oImageInfo.m_lID,
|
||||
(NSCommon::itJPG == pSpan->m_oImageInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
return;
|
||||
}
|
||||
CString strStyle1 = _T("");
|
||||
CString strStyle2 = _T("");
|
||||
|
||||
if (m_bIsFontsEmbedded)
|
||||
{
|
||||
CString strName = pSpan->m_oFont.Name;
|
||||
strName.Replace(_T(" "), _T("_avs_space_"));
|
||||
|
||||
strStyle1 = (_T("<span style=\"font-family:") + strName + _T(";"));
|
||||
if (pSpan->m_oFont.Bold)
|
||||
strStyle1 += _T("font-weight:bold;");
|
||||
else
|
||||
strStyle1 += _T("font-weight:normal;");
|
||||
|
||||
if (pSpan->m_oFont.Italic)
|
||||
strStyle1 += _T("font-style:italic;\">");
|
||||
else
|
||||
strStyle1 += _T("font-style:normal;\">");
|
||||
|
||||
strStyle2 = _T("</span>");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pSpan->m_oFont.Bold)
|
||||
{
|
||||
strStyle1 += _T("<b>");
|
||||
strStyle2 += _T("</b>");
|
||||
}
|
||||
if (pSpan->m_oFont.Italic)
|
||||
{
|
||||
strStyle1 += _T("<i>");
|
||||
strStyle2 = (_T("</i>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_oFont.Underline != 0)
|
||||
{
|
||||
strStyle1 += _T("<u>");
|
||||
strStyle2 = (_T("</u>") + strStyle2);
|
||||
}
|
||||
}
|
||||
|
||||
if (pSpan->m_dBaselineOffset < 0)
|
||||
{
|
||||
strStyle1 += _T("<sub>");
|
||||
strStyle2 = (_T("</sub>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_dBaselineOffset > 0)
|
||||
{
|
||||
strStyle1 += _T("<sup>");
|
||||
strStyle2 = (_T("</sup>") + strStyle2);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(strStyle1);
|
||||
m_oWriter.WriteTextXML(pSpan->m_oText);
|
||||
m_oWriter.WriteStringC(strStyle2);
|
||||
}
|
||||
AVSINLINE void WriteTable(NSEBook::CEbookTable* pTable)
|
||||
{
|
||||
m_oWriter.WriteString(pTable->m_strTableXml);
|
||||
if (pTable->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<div class=\"bookpagebreak\"/>"));
|
||||
}
|
||||
CheckSplitHtml();
|
||||
}
|
||||
AVSINLINE void WriteNumbering(NSEBook::CEbookNumbering* pNumbering)
|
||||
{
|
||||
CheckSplitHtml();
|
||||
}
|
||||
};
|
||||
}
|
||||
302
AVSEBOOKWriter2/Writers/Writer_Fb2.h
Normal file
302
AVSEBOOKWriter2/Writers/Writer_Fb2.h
Normal file
@ -0,0 +1,302 @@
|
||||
#pragma once
|
||||
#include "Writer.h"
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
class CWriter_Fb2
|
||||
{
|
||||
public:
|
||||
NSCommon::CStringWriter m_oWriter;
|
||||
|
||||
public:
|
||||
void CreateDocument(CWriter* pWriter)
|
||||
{
|
||||
m_oWriter.ClearNoAttack();
|
||||
|
||||
CFormat* pFormat = &pWriter->m_oFormat;
|
||||
|
||||
m_oWriter.WriteStringC(_T("<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
|
||||
m_oWriter.WriteStringC(_T("<FictionBook xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.gribuser.ru/xml/fictionbook/2.0\">"));
|
||||
|
||||
m_oWriter.WriteStringC(_T("<description><title-info>"));
|
||||
m_oWriter.WriteString(_T("<author><first-name></first-name><last-name>") + pFormat->m_oMeta.m_strAuthor + _T("</last-name></author>"));
|
||||
m_oWriter.WriteString(_T("<book-title>") + pFormat->m_oMeta.m_strName + _T("</book-title>"));
|
||||
m_oWriter.WriteString(_T("<lang>") + pFormat->m_oMeta.m_strLanguage + _T("</lang>"));
|
||||
|
||||
if (pWriter->m_bIsSaveCover)
|
||||
{
|
||||
CString strCover = _T("#image1.jpg");
|
||||
if (0 != pWriter->m_oFormat.m_oImageManager.m_listImages.GetCount())
|
||||
{
|
||||
if (NSCommon::itPNG == pWriter->m_oFormat.m_oImageManager.m_listImages.GetHead().m_eType)
|
||||
strCover = _T("#image1.png");
|
||||
}
|
||||
m_oWriter.WriteString(_T("<coverpage><image xlink:href=\"") + strCover + _T("\"/></coverpage>"));
|
||||
}
|
||||
|
||||
if (0 != pFormat->m_oMeta.m_listAnnotation.GetCount())
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<annotation>"));
|
||||
|
||||
POSITION pos = pFormat->m_oMeta.m_listAnnotation.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = pFormat->m_oMeta.m_listAnnotation.GetNext(pos);
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case IEbookItem::ebitParagraph:
|
||||
{
|
||||
WriteParagraph((CEbookParagraph*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitTable:
|
||||
{
|
||||
WriteTable((CEbookTable*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitGraphic:
|
||||
{
|
||||
WriteImage((CEbookGraphicObject*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitNumbering:
|
||||
{
|
||||
WriteNumbering((CEbookNumbering*)pItem);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</annotation>"));
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</title-info>"));
|
||||
|
||||
m_oWriter.WriteStringC(_T("<document-info><author><first-name></first-name><last-name></last-name></author><program-used>Online Media Technologies Ltd.</program-used><date value=\"2011-07-26\">26.07.2011</date><id>"));
|
||||
GUID guid;
|
||||
CoCreateGuid(&guid);
|
||||
CString strGuid = _T("");
|
||||
strGuid.Format(_T("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"), guid.Data1, guid.Data2, guid.Data3,
|
||||
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
||||
m_oWriter.WriteString(strGuid);
|
||||
m_oWriter.WriteStringC(_T("</id><version>1.0</version></document-info>"));
|
||||
|
||||
m_oWriter.WriteString(_T("<publish-info><publisher>") + pFormat->m_oMeta.m_strPublisher + _T("</publisher></publish-info></description>"));
|
||||
|
||||
m_oWriter.WriteString(_T("<body>"));
|
||||
|
||||
POSITION posSect = pFormat->m_listSections.GetHeadPosition();
|
||||
while (NULL != posSect)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<section>"));
|
||||
CSection& oSection = pFormat->m_listSections.GetNext(posSect);
|
||||
|
||||
POSITION pos = oSection.m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = oSection.m_arItems.GetNext(pos);
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case IEbookItem::ebitParagraph:
|
||||
{
|
||||
WriteParagraph((CEbookParagraph*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitTable:
|
||||
{
|
||||
WriteTable((CEbookTable*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitGraphic:
|
||||
{
|
||||
WriteImage((CEbookGraphicObject*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitNumbering:
|
||||
{
|
||||
WriteNumbering((CEbookNumbering*)pItem);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_oWriter.WriteStringC(_T("</section>"));
|
||||
}
|
||||
|
||||
m_oWriter.WriteString(_T("</body>"));
|
||||
}
|
||||
void CloseFile(CString strDstFile, CWriter* pWriter)
|
||||
{
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strDstFile);
|
||||
|
||||
CString strData = m_oWriter.GetCString();
|
||||
oFile.WriteStringUTF8(strData);
|
||||
|
||||
m_oWriter.Clear();
|
||||
|
||||
POSITION pos = pWriter->m_oFormat.m_oImageManager.m_mapImagesFile.GetStartPosition();
|
||||
CString strMedia = pWriter->m_oFormat.m_oTempManager.m_strTempImagesDirectory;
|
||||
while (NULL != pos)
|
||||
{
|
||||
CImageInfo& info = pWriter->m_oFormat.m_oImageManager.m_mapImagesFile.GetNextValue(pos);
|
||||
WriteImageToFile(oFile, info, strMedia);
|
||||
}
|
||||
pos = pWriter->m_oFormat.m_oImageManager.m_mapImageData.GetStartPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CImageInfo& info = pWriter->m_oFormat.m_oImageManager.m_mapImageData.GetNextValue(pos);
|
||||
WriteImageToFile(oFile, info, strMedia);
|
||||
}
|
||||
|
||||
CString strEnd = _T("</FictionBook>");
|
||||
oFile.WriteStringUTF8(strEnd);
|
||||
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
void WriteImageToFile(CFile& oFile, CImageInfo& info, CString& strMedia)
|
||||
{
|
||||
CFile oImageFile;
|
||||
oImageFile.OpenFile(info.GetPath(strMedia));
|
||||
int nInputLen = (int)oImageFile.GetFileSize();
|
||||
BYTE* pData = new BYTE[nInputLen];
|
||||
oImageFile.ReadFile(pData, nInputLen);
|
||||
|
||||
int nOutputLen = Base64EncodeGetRequiredLength(nInputLen);
|
||||
BYTE* pOutput = new BYTE[nOutputLen];
|
||||
Base64Encode(pData, nInputLen, (LPSTR)pOutput, &nOutputLen);
|
||||
|
||||
CString strBinary = _T("");
|
||||
if (itJPG == info.m_eType)
|
||||
strBinary.Format(_T("<binary content-type=\"image/jpg\" id=\"image%d.jpg\">"), info.m_lID);
|
||||
else
|
||||
strBinary.Format(_T("<binary content-type=\"image/png\" id=\"image%d.png\">"), info.m_lID);
|
||||
|
||||
oFile.WriteStringUTF8(strBinary);
|
||||
oFile.WriteFile((void*)pOutput, nOutputLen);
|
||||
CString strBinaryEnd = _T("</binary>");
|
||||
oFile.WriteStringUTF8(strBinaryEnd);
|
||||
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
RELEASEARRAYOBJECTS(pOutput);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
AVSINLINE void WriteImage(NSEBook::CEbookGraphicObject* pImage)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<image xlink:href=\"#image%d.%s\"/>"), pImage->m_oInfo.m_lID,
|
||||
(NSCommon::itJPG == pImage->m_oInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
}
|
||||
AVSINLINE void WriteParagraph(NSEBook::CEbookParagraph* pParagraph)
|
||||
{
|
||||
if (1 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<title>"));
|
||||
else if (2 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<subtitle>"));
|
||||
|
||||
m_oWriter.WriteStringC(_T("<p>"));
|
||||
NSEBook::CEbookParagraph::CSpan* pSpan = NULL;
|
||||
|
||||
POSITION posLine = pParagraph->m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CLine& oLine = pParagraph->m_arLines.GetNext(posLine);
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (NULL == pSpan)
|
||||
pSpan = &oSpan;
|
||||
else if (pSpan->m_oFont.IsEqual(&oSpan.m_oFont) && pSpan->m_oBrush.IsEqual(&oSpan.m_oBrush)
|
||||
&& (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
pSpan->m_oText += oSpan.m_oText;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
pSpan = &oSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != pSpan)
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</p>"));
|
||||
|
||||
if (1 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("</title>"));
|
||||
else if (2 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("</subtitle>"));
|
||||
}
|
||||
|
||||
AVSINLINE void WriteSpan(NSEBook::CEbookParagraph::CSpan* pSpan)
|
||||
{
|
||||
if (-1 != pSpan->m_oImageInfo.m_lID)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
strImage.Format(_T("<image xlink:href=\"#image%d.%s\"/>"), pSpan->m_oImageInfo.m_lID,
|
||||
(NSCommon::itJPG == pSpan->m_oImageInfo.m_eType) ? _T("jpg") : _T("png"));
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
return;
|
||||
}
|
||||
CString strStyle1 = _T("");
|
||||
CString strStyle2 = _T("");
|
||||
|
||||
if (pSpan->m_oFont.Bold)
|
||||
{
|
||||
strStyle1 += _T("<strong>");
|
||||
strStyle2 += _T("</strong>");
|
||||
}
|
||||
if (pSpan->m_oFont.Italic)
|
||||
{
|
||||
strStyle1 += _T("<emphasis>");
|
||||
strStyle2 = (_T("</emphasis>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_oFont.Strikeout != 0)
|
||||
{
|
||||
strStyle1 += _T("<strikethrough>");
|
||||
strStyle2 = (_T("</strikethrough>") + strStyle2);
|
||||
}
|
||||
|
||||
if (pSpan->m_dBaselineOffset < 0)
|
||||
{
|
||||
strStyle1 += _T("<sub>");
|
||||
strStyle2 = (_T("</sub>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_dBaselineOffset > 0)
|
||||
{
|
||||
strStyle1 += _T("<sup>");
|
||||
strStyle2 = (_T("</sup>") + strStyle2);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(strStyle1);
|
||||
m_oWriter.WriteTextXML(pSpan->m_oText);
|
||||
m_oWriter.WriteStringC(strStyle2);
|
||||
}
|
||||
AVSINLINE void WriteTable(NSEBook::CEbookTable* pTable)
|
||||
{
|
||||
m_oWriter.WriteString(pTable->m_strTableXml);
|
||||
}
|
||||
AVSINLINE void WriteNumbering(NSEBook::CEbookNumbering* pNumbering)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
831
AVSEBOOKWriter2/Writers/Writer_Mobi.h
Normal file
831
AVSEBOOKWriter2/Writers/Writer_Mobi.h
Normal file
@ -0,0 +1,831 @@
|
||||
#pragma once
|
||||
#include "Writer.h"
|
||||
#include "../MOBIFormat/MobiReader.h"
|
||||
|
||||
#define FCIS_FLIS TRUE
|
||||
|
||||
namespace NSEBook
|
||||
{
|
||||
#define TEXT_REC_LEN 4096
|
||||
class CWriter_Mobi
|
||||
{
|
||||
public:
|
||||
class CRecord
|
||||
{
|
||||
public:
|
||||
BYTE* m_pData;
|
||||
LONG m_lLen;
|
||||
|
||||
public:
|
||||
CRecord()
|
||||
{
|
||||
m_pData = NULL;
|
||||
m_lLen = 0;
|
||||
}
|
||||
~CRecord()
|
||||
{
|
||||
RELEASEARRAYOBJECTS(m_pData);
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
NSCommon::CStringWriter m_oWriter;
|
||||
bool m_bIsCompression;
|
||||
|
||||
CAtlList<CRecord*> m_arRecords;
|
||||
LONG m_lTextRecords;
|
||||
LONG m_lImageRecords;
|
||||
|
||||
CFormat* m_pFormat;
|
||||
bool m_bIsCover;
|
||||
bool m_bIsAdditionalTextRec;
|
||||
|
||||
public:
|
||||
CWriter_Mobi() : m_arRecords()
|
||||
{
|
||||
m_bIsCompression = true;
|
||||
}
|
||||
~CWriter_Mobi()
|
||||
{
|
||||
POSITION pos = m_arRecords.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CRecord* pRecord = m_arRecords.GetNext(pos);
|
||||
RELEASEOBJECT(pRecord);
|
||||
}
|
||||
m_arRecords.RemoveAll();
|
||||
}
|
||||
public:
|
||||
void CreateDocument(CWriter* pWriter)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> writer
|
||||
CString str1 = _T("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/><guide></guide>\n\
|
||||
<style type=\"text/css\">\n\
|
||||
.heading1 { text-align: center; font-weight: bold; font-size: 2em; }\n\
|
||||
.heading2 { text-align: center; font-weight: bold; font-size: 1.5em; }n\
|
||||
.heading0 { text-indent: 2em; text-align: justify; font-size: 1em; }\n\
|
||||
.image_inline { vertical-align: baseline; }\n\
|
||||
.image_block { vertical-align: baseline; }\n\
|
||||
.main { display: block; font-size: 1em; margin-bottom: 0; margin-left: 5pt; margin-right: 5pt; margin-top: 0; padding-left: 0; padding-right: 0; text-align: justify }\n\
|
||||
.hyper { text-decoration: underline; }\n\
|
||||
</style></head><body class=\"main\">");
|
||||
m_oWriter.WriteStringC(str1);
|
||||
|
||||
/*CString str1 = _T("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/><guide></guide>\n\
|
||||
</head><body>");
|
||||
m_oWriter.WriteStringC(str1);*/
|
||||
|
||||
m_bIsCover = pWriter->m_bIsSaveCover;
|
||||
|
||||
m_pFormat = &pWriter->m_oFormat;
|
||||
POSITION posSect = m_pFormat->m_listSections.GetHeadPosition();
|
||||
while (NULL != posSect)
|
||||
{
|
||||
CSection& oSection = m_pFormat->m_listSections.GetNext(posSect);
|
||||
|
||||
m_oWriter.WriteStringC(_T("<div><a/>"));
|
||||
|
||||
POSITION pos = oSection.m_arItems.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
IEbookItem* pItem = oSection.m_arItems.GetNext(pos);
|
||||
|
||||
switch (pItem->m_eType)
|
||||
{
|
||||
case IEbookItem::ebitParagraph:
|
||||
{
|
||||
WriteParagraph((CEbookParagraph*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitTable:
|
||||
{
|
||||
WriteTable((CEbookTable*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitGraphic:
|
||||
{
|
||||
WriteImage((CEbookGraphicObject*)pItem);
|
||||
break;
|
||||
}
|
||||
case IEbookItem::ebitNumbering:
|
||||
{
|
||||
WriteNumbering((CEbookNumbering*)pItem);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != posSect)
|
||||
m_oWriter.WriteStringC(_T("<mbp:pagebreak/></div>"));
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</body></html>"));
|
||||
|
||||
#ifdef _DEBUG
|
||||
CString strXml = m_oWriter.GetCString();
|
||||
CDirectory::SaveToFile(_T("C:\\debug_mobi.html"), strXml);
|
||||
#endif
|
||||
}
|
||||
void CloseFile(CString strDstFile, CWriter* pWriter)
|
||||
{
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strDstFile);
|
||||
|
||||
// -------------- DEBUG ------------------------------
|
||||
if (FALSE)
|
||||
{
|
||||
CFile oFileD;
|
||||
oFileD.OpenFile(_T("C:\\images.html"));
|
||||
CString strH = oFileD.ReadStringFromUTF8((DWORD)oFileD.GetFileSize());
|
||||
oFileD.CloseFile();
|
||||
m_oWriter.WriteString(strH);
|
||||
}
|
||||
// ---------------------------------------------------
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
CString strXml = m_oWriter.GetCString();
|
||||
int nLength = strXml.GetLength();
|
||||
|
||||
CStringA saStr;
|
||||
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, strXml.GetBuffer(), nLength + 1, saStr.GetBuffer(nLength*3 + 1), nLength*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
|
||||
LONG lSrcLen = saStr.GetLength();
|
||||
BYTE* pSrcBuffer = (BYTE*)saStr.GetBuffer();
|
||||
LONG lSrcCount = saStr.GetLength();
|
||||
|
||||
m_lImageRecords = (LONG)pWriter->m_oFormat.m_oImageManager.m_listImages.GetCount();
|
||||
|
||||
GenerateRecords(pWriter, pSrcBuffer, lSrcLen);
|
||||
GenerateRecord0(&pWriter->m_oFormat, lSrcLen);
|
||||
|
||||
CFormat* pFormat = &pWriter->m_oFormat;
|
||||
|
||||
LONG lRecCount = m_lTextRecords + m_lImageRecords + 1 + 1;
|
||||
if (FCIS_FLIS)
|
||||
lRecCount += 2;
|
||||
|
||||
NSMobi::CStream oStream;
|
||||
oStream.CreateFromBuffer(1000 + lRecCount * 8);
|
||||
|
||||
NSMobi::CMobiReader::CPDBHeader oHeader1;
|
||||
oHeader1.WriteToStream(&oStream, pFormat->m_oMeta.m_strName, lRecCount);
|
||||
|
||||
POSITION posRec = m_arRecords.GetHeadPosition();
|
||||
DWORD dwOffset = (DWORD)oStream.GetPosition() + lRecCount * 8;
|
||||
LONG i = 0;
|
||||
while (NULL != posRec)
|
||||
{
|
||||
CRecord* pRecord = m_arRecords.GetNext(posRec);
|
||||
|
||||
oStream.WriteDWORD(dwOffset);
|
||||
|
||||
DWORD dwFlag = (DWORD)(2 * i);
|
||||
dwFlag &= 0x00FFFFFF;
|
||||
|
||||
oStream.WriteDWORD(dwFlag);
|
||||
|
||||
dwOffset += (DWORD)pRecord->m_lLen;
|
||||
++i;
|
||||
}
|
||||
|
||||
oStream.DumpToFile(oFile);
|
||||
|
||||
posRec = m_arRecords.GetHeadPosition();
|
||||
while (NULL != posRec)
|
||||
{
|
||||
CRecord* pRecord = m_arRecords.GetNext(posRec);
|
||||
oFile.WriteFile((void*)pRecord->m_pData, pRecord->m_lLen);
|
||||
}
|
||||
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void GenerateRecords(CWriter* pWriter, BYTE* pSrcBuffer, LONG lSrcLen)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE* inputStart = pSrcBuffer;
|
||||
LONG lCurrentLenTail = lSrcLen;
|
||||
|
||||
LONG lDataSize = 0;
|
||||
while (lCurrentLenTail > 0)
|
||||
{
|
||||
BYTE* current = inputStart;
|
||||
|
||||
LONG lCurrentRecLen = 0;
|
||||
while (lCurrentLenTail > 0)
|
||||
{
|
||||
if (0x00 == (0x80 & *current))
|
||||
{
|
||||
++current;
|
||||
++lCurrentRecLen;
|
||||
|
||||
--lCurrentLenTail;
|
||||
}
|
||||
else if (0x00 == (0x20 & *current))
|
||||
{
|
||||
current += 2;
|
||||
lCurrentRecLen += 2;
|
||||
|
||||
lCurrentLenTail -= 2;
|
||||
}
|
||||
else if (0x00 == (0x10 & *current))
|
||||
{
|
||||
current += 3;
|
||||
lCurrentRecLen += 3;
|
||||
|
||||
lCurrentLenTail -= 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
++current;
|
||||
++lCurrentRecLen;
|
||||
|
||||
--lCurrentLenTail;
|
||||
}
|
||||
|
||||
if (lCurrentRecLen >= TEXT_REC_LEN)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lCurrentRecLen == TEXT_REC_LEN)
|
||||
{
|
||||
if (!m_bIsCompression)
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_pData = new BYTE[TEXT_REC_LEN];
|
||||
pRecord->m_lLen = TEXT_REC_LEN;
|
||||
memcpy(pRecord->m_pData, inputStart, TEXT_REC_LEN);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
NSMobi::CTextDecoder::PalmEncode(inputStart, TEXT_REC_LEN, pRecord->m_pData, pRecord->m_lLen, TEXT_REC_LEN);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
}
|
||||
else if (lCurrentRecLen > TEXT_REC_LEN)
|
||||
{
|
||||
if (!m_bIsCompression)
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_pData = new BYTE[lCurrentRecLen];
|
||||
pRecord->m_lLen = lCurrentRecLen;
|
||||
memcpy(pRecord->m_pData, inputStart, lCurrentRecLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
NSMobi::CTextDecoder::PalmEncode(inputStart, TEXT_REC_LEN, pRecord->m_pData, pRecord->m_lLen, lCurrentRecLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FALSE)
|
||||
{
|
||||
BYTE* pData = new BYTE[TEXT_REC_LEN];
|
||||
memset(pData, 32, TEXT_REC_LEN);
|
||||
memcpy(pData, inputStart, lCurrentRecLen);
|
||||
|
||||
if (!m_bIsCompression)
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_pData = pData;
|
||||
pRecord->m_lLen = TEXT_REC_LEN;
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
NSMobi::CTextDecoder::PalmEncode(pData, lCurrentRecLen, pRecord->m_pData, pRecord->m_lLen, TEXT_REC_LEN);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_bIsCompression)
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_pData = new BYTE[lCurrentRecLen];
|
||||
pRecord->m_lLen = lCurrentRecLen;
|
||||
memcpy(pRecord->m_pData, inputStart, lCurrentRecLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
NSMobi::CTextDecoder::PalmEncode(inputStart, lCurrentRecLen, pRecord->m_pData, pRecord->m_lLen, lCurrentRecLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
lDataSize += pRecord->m_lLen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inputStart = current;
|
||||
}
|
||||
|
||||
m_bIsAdditionalTextRec = false;
|
||||
|
||||
m_lTextRecords = (LONG)m_arRecords.GetCount();
|
||||
|
||||
/*
|
||||
LONG lModule4 = lDataSize % 4;
|
||||
if (0 != lModule4)
|
||||
{
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_pData = new BYTE[pRecord->m_lLen];
|
||||
memset(pRecord->m_pData, 0, pRecord->m_lLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
m_bIsAdditionalTextRec = true;
|
||||
}
|
||||
*/
|
||||
|
||||
NSCommon::CImageManager* pManager = &pWriter->m_oFormat.m_oImageManager;
|
||||
CString strMediaPath = pWriter->m_oFormat.m_oTempManager.m_strTempImagesDirectory;
|
||||
POSITION posImage = pManager->m_listImages.GetHeadPosition();
|
||||
while (NULL != posImage)
|
||||
{
|
||||
NSCommon::CImageInfo& info = pManager->m_listImages.GetNext(posImage);
|
||||
|
||||
CFile oImageFile;
|
||||
oImageFile.OpenFile(info.GetPath(strMediaPath));
|
||||
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_lLen = (LONG)oImageFile.GetFileSize();
|
||||
pRecord->m_pData = new BYTE[pRecord->m_lLen];
|
||||
oImageFile.ReadFile(pRecord->m_pData, (DWORD)pRecord->m_lLen);
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
oImageFile.CloseFile();
|
||||
}
|
||||
|
||||
GenerateEndRecords(lSrcLen);
|
||||
}
|
||||
|
||||
void GenerateRecord0(NSEBook::CFormat* pFormat, LONG lSrcTextLen)
|
||||
{
|
||||
LONG lRecCount = m_lTextRecords + m_lImageRecords + 1 + 1;
|
||||
if (FCIS_FLIS)
|
||||
lRecCount += 2;
|
||||
|
||||
NSMobi::CStream oStream;
|
||||
oStream.CreateFromBuffer(1024 * 1024); // 1mb
|
||||
|
||||
// mobiheader
|
||||
if (m_bIsCompression)
|
||||
oStream.WriteUShort(2);
|
||||
else
|
||||
oStream.WriteUShort(1);
|
||||
|
||||
oStream.WriteUShort(0);
|
||||
oStream.WriteLong(lSrcTextLen);
|
||||
oStream.WriteUShort((USHORT)(m_lTextRecords));
|
||||
oStream.WriteUShort(4096);
|
||||
oStream.WriteUShort(0);
|
||||
oStream.WriteUShort(0);
|
||||
|
||||
DWORD uid = rand();
|
||||
|
||||
oStream.WriteCStringA("MOBI");
|
||||
oStream.WriteDWORD(0xE8);
|
||||
oStream.WriteDWORD(0x02);
|
||||
oStream.WriteDWORD(65001);
|
||||
oStream.WriteDWORD(uid);
|
||||
oStream.WriteDWORD(0x06);
|
||||
|
||||
oStream.WriteSet(0xFF, 8);
|
||||
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
|
||||
oStream.WriteSet(0xFF, 28);
|
||||
|
||||
NSMobi::CStream oStreamEXTH;
|
||||
NSMobi::CStream oStreamTITLE;
|
||||
oStreamEXTH.CreateFromBuffer(1024 * 5);
|
||||
oStreamTITLE.CreateFromBuffer(1024 * 5);
|
||||
|
||||
GenerateEXTH(oStreamEXTH, pFormat);
|
||||
GenerateTITLE(oStreamTITLE, pFormat);
|
||||
|
||||
oStream.WriteDWORD((DWORD)(m_lTextRecords + 1));
|
||||
oStream.WriteDWORD((DWORD)(0xe8 + 16 + oStreamEXTH.GetPosition()));
|
||||
oStream.WriteDWORD((DWORD)oStreamTITLE.GetPosition());
|
||||
|
||||
oStream.WriteDWORD(0);
|
||||
|
||||
oStream.WriteSet(0, 8);
|
||||
|
||||
oStream.WriteDWORD(6);
|
||||
|
||||
if (0 == m_lImageRecords)
|
||||
oStream.WriteDWORD(0);
|
||||
else
|
||||
oStream.WriteDWORD(m_lTextRecords + 1);
|
||||
|
||||
oStream.WriteSet(0, 16);
|
||||
|
||||
oStream.WriteDWORD(0x50);
|
||||
oStream.WriteSet(0, 32);
|
||||
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(0);
|
||||
oStream.WriteDWORD(0);
|
||||
|
||||
oStream.WriteSet(0, 12);
|
||||
oStream.WriteUShort(1);
|
||||
oStream.WriteUShort((USHORT)(lRecCount - 1));
|
||||
|
||||
oStream.WriteByte(0);
|
||||
oStream.WriteByte(0);
|
||||
oStream.WriteByte(0);
|
||||
oStream.WriteByte(1);
|
||||
|
||||
if (FCIS_FLIS)
|
||||
{
|
||||
oStream.WriteDWORD((DWORD)(m_lImageRecords + m_lTextRecords + 2));
|
||||
oStream.WriteDWORD(1);
|
||||
oStream.WriteDWORD((DWORD)(m_lImageRecords + m_lTextRecords + 1));
|
||||
oStream.WriteDWORD(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(1);
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(1);
|
||||
}
|
||||
|
||||
oStream.WriteSet(0, 8);
|
||||
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(0x00);
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
|
||||
oStream.WriteDWORD(1);
|
||||
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
|
||||
oStream.Write(&oStreamEXTH);
|
||||
oStream.Write(&oStreamTITLE);
|
||||
|
||||
if (TRUE)
|
||||
{
|
||||
//oStream.WriteSet(0, 1024 * 8);
|
||||
oStream.WriteSet(0, 8);
|
||||
}
|
||||
|
||||
int nPos = oStream.GetPosition();
|
||||
int mod = nPos % 4;
|
||||
if (0 != mod)
|
||||
oStream.WriteSet(0, 4 - mod);
|
||||
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_lLen = oStream.GetPosition();
|
||||
pRecord->m_pData = new BYTE[pRecord->m_lLen];
|
||||
memcpy(pRecord->m_pData, oStream.GetData(), pRecord->m_lLen);
|
||||
m_arRecords.AddHead(pRecord);
|
||||
}
|
||||
|
||||
void GenerateEndRecords(LONG lTextLength)
|
||||
{
|
||||
if (FCIS_FLIS)
|
||||
{
|
||||
NSMobi::CStream oStream;
|
||||
oStream.FromBuffer(new BYTE[100], 100);
|
||||
|
||||
oStream.WriteCStringA("FLIS");
|
||||
oStream.WriteDWORD(0x08);
|
||||
oStream.WriteUShort(0x41);
|
||||
oStream.WriteDWORD(0x00);
|
||||
oStream.WriteDWORD(0xFFFF);
|
||||
oStream.WriteUShort(0xFFFF);
|
||||
oStream.WriteDWORD(0x00010003);
|
||||
oStream.WriteDWORD(0x03);
|
||||
oStream.WriteDWORD(0x01);
|
||||
oStream.WriteDWORD(0xFFFFFFFF);
|
||||
|
||||
CRecord* pRecord = new CRecord();
|
||||
pRecord->m_lLen = (LONG)oStream.GetPosition();
|
||||
pRecord->m_pData = new BYTE[pRecord->m_lLen];
|
||||
memcpy(pRecord->m_pData, oStream.GetData(), pRecord->m_lLen);
|
||||
|
||||
m_arRecords.AddTail(pRecord);
|
||||
|
||||
oStream.Seek(0);
|
||||
|
||||
oStream.WriteCStringA("FCIS");
|
||||
oStream.WriteDWORD(0x14);
|
||||
oStream.WriteDWORD(0x10);
|
||||
oStream.WriteDWORD(0x01);
|
||||
oStream.WriteDWORD(0x00);
|
||||
oStream.WriteDWORD((DWORD)lTextLength);
|
||||
oStream.WriteDWORD(0x00);
|
||||
oStream.WriteDWORD(0x20);
|
||||
oStream.WriteDWORD(0x08);
|
||||
oStream.WriteDWORD(0x00010001);
|
||||
oStream.WriteDWORD(0x00);
|
||||
|
||||
CRecord* pRecord2 = new CRecord();
|
||||
pRecord2->m_lLen = (LONG)oStream.GetPosition();
|
||||
pRecord2->m_pData = new BYTE[pRecord2->m_lLen];
|
||||
memcpy(pRecord2->m_pData, oStream.GetData(), pRecord2->m_lLen);
|
||||
|
||||
m_arRecords.AddTail(pRecord2);
|
||||
|
||||
CRecord* pRecordEnd = new CRecord();
|
||||
pRecordEnd->m_lLen = 4;
|
||||
pRecordEnd->m_pData = new BYTE[4];
|
||||
pRecordEnd->m_pData[0] = 0xE9;
|
||||
pRecordEnd->m_pData[0] = 0x8E;
|
||||
pRecordEnd->m_pData[0] = 0x0D;
|
||||
pRecordEnd->m_pData[0] = 0x0A;
|
||||
|
||||
m_arRecords.AddTail(pRecordEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecord* pRecordEnd = new CRecord();
|
||||
pRecordEnd->m_lLen = 4;
|
||||
pRecordEnd->m_pData = new BYTE[4];
|
||||
pRecordEnd->m_pData[0] = 0xE9;
|
||||
pRecordEnd->m_pData[0] = 0x8E;
|
||||
pRecordEnd->m_pData[0] = 0x0D;
|
||||
pRecordEnd->m_pData[0] = 0x0A;
|
||||
|
||||
m_arRecords.AddTail(pRecordEnd);
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateEXTH(NSMobi::CStream& oStream, NSEBook::CFormat* pFormat)
|
||||
{
|
||||
oStream.WriteCStringA("EXTH");
|
||||
|
||||
BYTE* pDataLen = oStream.GetCurrentData();
|
||||
oStream.WriteDWORD(0);
|
||||
oStream.WriteDWORD(0);
|
||||
|
||||
DWORD dwCountRecords = 0;
|
||||
if (_T("") != pFormat->m_oMeta.m_strAuthor)
|
||||
{
|
||||
CStringA strAuthor = ConverToUTF8(pFormat->m_oMeta.m_strAuthor);
|
||||
NSMobi::CMobiReader::CEXTHHeader::WriteRec(oStream, 100, strAuthor);
|
||||
++dwCountRecords;
|
||||
}
|
||||
if (_T("") != pFormat->m_oMeta.m_strCreatorProgram)
|
||||
{
|
||||
CStringA strAuthor = ConverToUTF8(pFormat->m_oMeta.m_strCreatorProgram);
|
||||
NSMobi::CMobiReader::CEXTHHeader::WriteRec(oStream, 108, strAuthor);
|
||||
++dwCountRecords;
|
||||
}
|
||||
if (_T("") != pFormat->m_oMeta.m_strPublisher)
|
||||
{
|
||||
CStringA strAuthor = ConverToUTF8(pFormat->m_oMeta.m_strPublisher);
|
||||
NSMobi::CMobiReader::CEXTHHeader::WriteRec(oStream, 101, strAuthor);
|
||||
++dwCountRecords;
|
||||
}
|
||||
if (m_bIsCover)
|
||||
{
|
||||
NSMobi::CMobiReader::CEXTHHeader::WriteRec(oStream, 201, (DWORD)0);
|
||||
++dwCountRecords;
|
||||
}
|
||||
if (0 != pFormat->m_oMeta.m_listAnnotation.GetCount())
|
||||
{
|
||||
CString strAnno = _T("");
|
||||
POSITION pos = pFormat->m_oMeta.m_listAnnotation.GetHeadPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
NSEBook::IEbookItem* pItem = pFormat->m_oMeta.m_listAnnotation.GetNext(pos);
|
||||
if (NSEBook::IEbookItem::ebitParagraph == pItem->m_eType)
|
||||
{
|
||||
strAnno += _T("<p>");
|
||||
strAnno += CorrectString2(((NSEBook::CEbookParagraph*)pItem)->GetAllText());
|
||||
strAnno += _T("</p>");
|
||||
}
|
||||
}
|
||||
|
||||
CStringA strAnnoA = ConverToUTF8(strAnno);
|
||||
NSMobi::CMobiReader::CEXTHHeader::WriteRec(oStream, 103, strAnnoA);
|
||||
++dwCountRecords;
|
||||
}
|
||||
|
||||
LONG lLen = oStream.GetPosition();
|
||||
LONG lPad = 4 - (lLen % 4);
|
||||
|
||||
DWORD dwSize1 = (DWORD)(lLen + 12);
|
||||
DWORD dwSize2 = dwCountRecords;
|
||||
|
||||
*pDataLen = (BYTE)(dwSize1 >> 24);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)(dwSize1 >> 16);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)(dwSize1 >> 8);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)dwSize1;
|
||||
++pDataLen;
|
||||
|
||||
*pDataLen = (BYTE)(dwSize2 >> 24);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)(dwSize2 >> 16);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)(dwSize2 >> 8);
|
||||
++pDataLen;
|
||||
*pDataLen = (BYTE)dwSize2;
|
||||
++pDataLen;
|
||||
|
||||
if (4 != lPad)
|
||||
oStream.WriteSet(0, lPad);
|
||||
}
|
||||
|
||||
void GenerateTITLE(NSMobi::CStream& oStream, NSEBook::CFormat* pFormat)
|
||||
{
|
||||
CStringA str = ConverToUTF8(pFormat->m_oMeta.m_strName);
|
||||
oStream.WriteCStringA(str);
|
||||
}
|
||||
|
||||
CStringA ConverToUTF8(CString& strXml)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
int nLength = strXml.GetLength();
|
||||
|
||||
CStringA saStr;
|
||||
|
||||
// Encoding Unicode to UTF-8
|
||||
WideCharToMultiByte(CP_UTF8, 0, strXml.GetBuffer(), nLength + 1, saStr.GetBuffer(nLength*3 + 1), nLength*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
|
||||
return saStr;
|
||||
}
|
||||
|
||||
/////////
|
||||
AVSINLINE void WriteImage(NSEBook::CEbookGraphicObject* pImage)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
LONG width = (LONG)(c_dpiBook * pImage->m_rcBounds.GetWidth() / c_dInchToMM);
|
||||
LONG height = (LONG)(c_dpiBook * pImage->m_rcBounds.GetHeight() / c_dInchToMM);
|
||||
strImage.Format(_T("<img recindex=\"%d\" align=\"baseline\" height=\"%d\" width=\"%d\" alt=\"\"/>"), pImage->m_oInfo.m_lID,
|
||||
height, width);
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
|
||||
if (pImage->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<mbp:pagebreak/>"));
|
||||
}
|
||||
}
|
||||
AVSINLINE void WriteParagraph(NSEBook::CEbookParagraph* pParagraph)
|
||||
{
|
||||
if (1 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading1\">"));
|
||||
else if (2 == pParagraph->m_lStyle)
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading2\">"));
|
||||
else
|
||||
{
|
||||
if (0 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\">"));
|
||||
}
|
||||
else if (1 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\" style=\"text-align:center;\">"));
|
||||
}
|
||||
else if (2 == pParagraph->m_lTextAlign)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\" style=\"text-align:right;\">"));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<p class=\"heading0\">"));
|
||||
}
|
||||
}
|
||||
|
||||
NSEBook::CEbookParagraph::CSpan* pSpan = NULL;
|
||||
|
||||
POSITION posLine = pParagraph->m_arLines.GetHeadPosition();
|
||||
while (NULL != posLine)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CLine& oLine = pParagraph->m_arLines.GetNext(posLine);
|
||||
|
||||
POSITION posSpan = oLine.m_listSpans.GetHeadPosition();
|
||||
while (NULL != posSpan)
|
||||
{
|
||||
NSEBook::CEbookParagraph::CSpan& oSpan = oLine.m_listSpans.GetNext(posSpan);
|
||||
if ((NULL == posSpan) && (NULL != posLine))
|
||||
oSpan.m_oText.CheckLastSpanLine();
|
||||
|
||||
if (NULL == pSpan)
|
||||
pSpan = &oSpan;
|
||||
else if (pSpan->m_oFont.IsEqual(&oSpan.m_oFont) && pSpan->m_oBrush.IsEqual(&oSpan.m_oBrush)
|
||||
&& (oSpan.m_oImageInfo.m_lID == -1) && (pSpan->m_oImageInfo.m_lID == -1))
|
||||
{
|
||||
pSpan->m_oText += oSpan.m_oText;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
pSpan = &oSpan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != pSpan)
|
||||
{
|
||||
WriteSpan(pSpan);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(_T("</p>"));
|
||||
|
||||
if (pParagraph->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<mbp:pagebreak/>"));
|
||||
}
|
||||
}
|
||||
|
||||
AVSINLINE void WriteSpan(NSEBook::CEbookParagraph::CSpan* pSpan)
|
||||
{
|
||||
if (-1 != pSpan->m_oImageInfo.m_lID)
|
||||
{
|
||||
CString strImage = _T("");
|
||||
LONG width = (LONG)(c_dpiBook * pSpan->m_dImageWidth / c_dInchToMM);
|
||||
LONG height = (LONG)(c_dpiBook * pSpan->m_dImageHeight / c_dInchToMM);
|
||||
strImage.Format(_T("<img recindex=\"%d\" align=\"baseline\" height=\"%d\" width=\"%d\" alt=\"\"/>"), pSpan->m_oImageInfo.m_lID,
|
||||
height, width);
|
||||
m_oWriter.WriteStringC(strImage);
|
||||
return;
|
||||
}
|
||||
CString strStyle1 = _T("");
|
||||
CString strStyle2 = _T("");
|
||||
|
||||
if (pSpan->m_oFont.Bold)
|
||||
{
|
||||
strStyle1 += _T("<b>");
|
||||
strStyle2 += _T("</b>");
|
||||
}
|
||||
if (pSpan->m_oFont.Italic)
|
||||
{
|
||||
strStyle1 += _T("<i>");
|
||||
strStyle2 = (_T("</i>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_oFont.Underline != 0)
|
||||
{
|
||||
strStyle1 += _T("<u>");
|
||||
strStyle2 = (_T("</u>") + strStyle2);
|
||||
}
|
||||
|
||||
if (pSpan->m_dBaselineOffset < 0)
|
||||
{
|
||||
strStyle1 += _T("<sub>");
|
||||
strStyle2 = (_T("</sub>") + strStyle2);
|
||||
}
|
||||
if (pSpan->m_dBaselineOffset > 0)
|
||||
{
|
||||
strStyle1 += _T("<sup>");
|
||||
strStyle2 = (_T("</sup>") + strStyle2);
|
||||
}
|
||||
|
||||
m_oWriter.WriteStringC(strStyle1);
|
||||
m_oWriter.WriteTextHTML(pSpan->m_oText);
|
||||
m_oWriter.WriteStringC(strStyle2);
|
||||
}
|
||||
AVSINLINE void WriteTable(NSEBook::CEbookTable* pTable)
|
||||
{
|
||||
m_oWriter.WriteString(pTable->m_strTableXml);
|
||||
|
||||
if (pTable->m_bIsPageBreakAfter)
|
||||
{
|
||||
m_oWriter.WriteStringC(_T("<mbp:pagebreak/>"));
|
||||
}
|
||||
}
|
||||
AVSINLINE void WriteNumbering(NSEBook::CEbookNumbering* pNumbering)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
17
AVSEBOOKWriter2/resource.h
Normal file
17
AVSEBOOKWriter2/resource.h
Normal file
@ -0,0 +1,17 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by AVSEBOOKWriter.rc
|
||||
//
|
||||
#define IDS_PROJNAME 100
|
||||
#define IDR_AVSEBOOKWRITER 101
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 209
|
||||
#define _APS_NEXT_COMMAND_VALUE 32768
|
||||
#define _APS_NEXT_CONTROL_VALUE 201
|
||||
#define _APS_NEXT_SYMED_VALUE 102
|
||||
#endif
|
||||
#endif
|
||||
5
AVSEBOOKWriter2/stdafx.cpp
Normal file
5
AVSEBOOKWriter2/stdafx.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// AVSEBOOKWriter.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
56
AVSEBOOKWriter2/stdafx.h
Normal file
56
AVSEBOOKWriter2/stdafx.h
Normal file
@ -0,0 +1,56 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently,
|
||||
// but are changed infrequently
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef STRICT
|
||||
#define STRICT
|
||||
#endif
|
||||
|
||||
// Modify the following defines if you have to target a platform prior to the ones specified below.
|
||||
// Refer to MSDN for the latest info on corresponding values for different platforms.
|
||||
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
|
||||
#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
|
||||
#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 2000 or later.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
|
||||
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
|
||||
#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later.
|
||||
#endif
|
||||
|
||||
#define _ATL_APARTMENT_THREADED
|
||||
#define _ATL_NO_AUTOMATIC_NAMESPACE
|
||||
|
||||
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
|
||||
|
||||
// turns off ATL's hiding of some common and often safely ignored warning messages
|
||||
#define _ATL_ALL_WARNINGS
|
||||
|
||||
#include <atlbase.h>
|
||||
#include <atlcom.h>
|
||||
#include <atlwin.h>
|
||||
#include <atltypes.h>
|
||||
#include <atlctl.h>
|
||||
#include <atlhost.h>
|
||||
|
||||
using namespace ATL;
|
||||
|
||||
#define DOCX_RENDERER
|
||||
//#define _USE_XMLLITE_READER_
|
||||
|
||||
#import "..\..\..\Redist\AVSGraphics.dll" named_guids raw_interfaces_only rename_namespace("AVSGraphics")
|
||||
#import "..\..\..\Redist\AVSMediaCore3.dll" named_guids raw_interfaces_only rename_namespace("MediaCore"), exclude("tagRECT")
|
||||
#import "..\..\..\Redist\AVSMediaFormatSettings3.dll" named_guids raw_interfaces_only rename_namespace("MediaFormat"), exclude("tagRECT")
|
||||
#import "..\..\..\Redist\AVSImageStudio3.dll" named_guids raw_interfaces_only rename_namespace("ImageStudio")
|
||||
#import "..\..\..\Redist\AVSOfficeStudio\AVSOfficeUtils.dll" named_guids rename_namespace("AVSOfficeUtils"), raw_interfaces_only
|
||||
|
||||
#import "..\..\..\Redist\AVSOfficeStudio\AVSOfficeHtmlFile.dll" raw_interfaces_only rename_namespace("OfficeHtmlFile")
|
||||
#import "..\..\..\Redist\AVSOfficeStudio\AVSOfficeTxtFile.dll" raw_interfaces_only rename_namespace("OfficeTxtFile")
|
||||
7
AVSEBOOKWriter2/version.h
Normal file
7
AVSEBOOKWriter2/version.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
//1
|
||||
//0
|
||||
//0
|
||||
//13
|
||||
#define INTVER 1,0,0,13
|
||||
#define STRVER "1,0,0,13\0"
|
||||
18
AVSFontConverter/AVSFontConverter.cpp
Normal file
18
AVSFontConverter/AVSFontConverter.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// AVSFontConverter.cpp : Implementation of DLL Exports.
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "resource.h"
|
||||
|
||||
|
||||
// The module attribute causes DllMain, DllRegisterServer and DllUnregisterServer to be automatically implemented for you
|
||||
[ module(dll, uuid = "{0F344B85-C7D3-483A-BA29-3ABFD701ADD0}",
|
||||
name = "AVSFontConverter",
|
||||
helpstring = "AVSFontConverter 1.0 Type Library",
|
||||
resource_name = "IDR_AVSFONTCONVERTER") ]
|
||||
class CAVSFontConverterModule
|
||||
{
|
||||
public:
|
||||
// Override CAtlDllModuleT members
|
||||
};
|
||||
|
||||
101
AVSFontConverter/AVSFontConverter.rc
Normal file
101
AVSFontConverter/AVSFontConverter.rc
Normal file
@ -0,0 +1,101 @@
|
||||
//Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
#define COMPONENT_NAME "FontConverter"
|
||||
#include "../../../../Common/FileInfo.h"
|
||||
#include "version.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
LANGUAGE 25, 1
|
||||
#pragma code_page(1251)
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""winres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION INTVER
|
||||
PRODUCTVERSION INTVER
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904B0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", COMPANY_NAME
|
||||
VALUE "FileDescription", FILE_DESCRIPTION_ACTIVEX
|
||||
VALUE "FileVersion", STRVER
|
||||
VALUE "LegalCopyright", LEGAL_COPYRIGHT
|
||||
VALUE "InternalName", COMPONENT_FILE_NAME_DLL
|
||||
VALUE "OriginalFilename", COMPONENT_FILE_NAME_DLL
|
||||
VALUE "ProductName", FILE_DESCRIPTION_ACTIVEX
|
||||
VALUE "ProductVersion", STRVER
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0409, 0x04B0
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_PROJNAME "AVSFontConverter"
|
||||
END
|
||||
|
||||
IDR_AVSFONTCONVERTER REGISTRY "AVSFontConverter.rgs"
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
11
AVSFontConverter/AVSFontConverter.rgs
Normal file
11
AVSFontConverter/AVSFontConverter.rgs
Normal file
@ -0,0 +1,11 @@
|
||||
HKCR
|
||||
{
|
||||
NoRemove AppID
|
||||
{
|
||||
'%APPID%' = s 'AVSFontConverter'
|
||||
'AVSFontConverter.DLL'
|
||||
{
|
||||
val AppID = s '%APPID%'
|
||||
}
|
||||
}
|
||||
}
|
||||
20
AVSFontConverter/AVSFontConverter.sln
Normal file
20
AVSFontConverter/AVSFontConverter.sln
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AVSFontConverter", "AVSFontConverter.vcproj", "{BC0A8A11-2017-473D-8AB1-86A55116A2F5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BC0A8A11-2017-473D-8AB1-86A55116A2F5}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{BC0A8A11-2017-473D-8AB1-86A55116A2F5}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{BC0A8A11-2017-473D-8AB1-86A55116A2F5}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{BC0A8A11-2017-473D-8AB1-86A55116A2F5}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
284
AVSFontConverter/AVSFontConverter.vcproj
Normal file
284
AVSFontConverter/AVSFontConverter.vcproj
Normal file
@ -0,0 +1,284 @@
|
||||
<?xml version="1.0" encoding="windows-1251"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9,00"
|
||||
Name="AVSFontConverter"
|
||||
ProjectGUID="{BC0A8A11-2017-473D-8AB1-86A55116A2F5}"
|
||||
Keyword="AtlProj"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="2"
|
||||
UseOfATL="1"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
MkTypLibCompatible="false"
|
||||
TargetEnvironment="1"
|
||||
GenerateStublessProxies="true"
|
||||
TypeLibraryName="$(IntDir)/AVSFontConverter.tlb"
|
||||
HeaderFileName="AVSFontConverter.h"
|
||||
DLLDataFileName=""
|
||||
InterfaceIdentifierFileName="AVSFontConverter_i.c"
|
||||
ProxyFileName="AVSFontConverter_p.c"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;_USRDLL;_ATL_ATTRIBUTES"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1049"
|
||||
AdditionalIncludeDirectories="$(IntDir)"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="true"
|
||||
OutputFile="$(OutDir)/AVSFontConverter.dll"
|
||||
LinkIncremental="2"
|
||||
MergedIDLBaseFileName="_AVSFontConverter.idl"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
ImportLibrary="$(OutDir)/AVSFontConverter.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="Performing registration"
|
||||
CommandLine="regsvr32 /s /c "$(TargetPath)""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="2"
|
||||
UseOfATL="1"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
CommandLine="X:\AVS\Redist\VersionControl.exe "$(SolutionDir)\version.h""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
MkTypLibCompatible="false"
|
||||
TargetEnvironment="1"
|
||||
GenerateStublessProxies="true"
|
||||
TypeLibraryName="$(IntDir)/AVSFontConverter.tlb"
|
||||
HeaderFileName="AVSFontConverter.h"
|
||||
DLLDataFileName=""
|
||||
InterfaceIdentifierFileName="AVSFontConverter_i.c"
|
||||
ProxyFileName="AVSFontConverter_p.c"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;_USRDLL;_ATL_ATTRIBUTES"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1049"
|
||||
AdditionalIncludeDirectories="$(IntDir)"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="true"
|
||||
OutputFile="../../../Redist/AVSOfficeStudio/AVSFontConverter.dll"
|
||||
LinkIncremental="1"
|
||||
MergedIDLBaseFileName="_AVSFontConverter.idl"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(OutDir)$(TargetName).pdb"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
ImportLibrary="$(OutDir)/AVSFontConverter.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="Performing registration"
|
||||
CommandLine="regsvr32 /s /c "$(TargetPath)""
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\AVSFontConverter.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontConverter.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\FontConverter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\version.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\AVSFontConverter.rc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\AVSFontConverter.rgs"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
22
AVSFontConverter/AVSFontConverter_vs2005.sln
Normal file
22
AVSFontConverter/AVSFontConverter_vs2005.sln
Normal file
@ -0,0 +1,22 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AVSFontConverter", "AVSFontConverter_vs2005.vcproj", "{BC0A8A11-2017-473D-8AB1-86A55116A2F5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
ReleaseASC|Win32 = ReleaseASC|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BC0A8A11-2017-473D-8AB1-86A55116A2F5}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{BC0A8A11-2017-473D-8AB1-86A55116A2F5}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{BC0A8A11-2017-473D-8AB1-86A55116A2F5}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{BC0A8A11-2017-473D-8AB1-86A55116A2F5}.Release|Win32.Build.0 = Release|Win32
|
||||
{BC0A8A11-2017-473D-8AB1-86A55116A2F5}.ReleaseASC|Win32.ActiveCfg = ReleaseASC|Win32
|
||||
{BC0A8A11-2017-473D-8AB1-86A55116A2F5}.ReleaseASC|Win32.Build.0 = ReleaseASC|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
465
AVSFontConverter/AVSFontConverter_vs2005.vcproj
Normal file
465
AVSFontConverter/AVSFontConverter_vs2005.vcproj
Normal file
@ -0,0 +1,465 @@
|
||||
<?xml version="1.0" encoding="windows-1251"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Name="AVSFontConverter"
|
||||
ProjectGUID="{BC0A8A11-2017-473D-8AB1-86A55116A2F5}"
|
||||
Keyword="AtlProj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="2"
|
||||
UseOfATL="1"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
MkTypLibCompatible="false"
|
||||
TargetEnvironment="1"
|
||||
GenerateStublessProxies="true"
|
||||
TypeLibraryName="$(IntDir)/AVSFontConverter.tlb"
|
||||
HeaderFileName="AVSFontConverter.h"
|
||||
DLLDataFileName=""
|
||||
InterfaceIdentifierFileName="AVSFontConverter_i.c"
|
||||
ProxyFileName="AVSFontConverter_p.c"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\AVSImageStudio3\AVSGraphics\Objects\Font\FreeType\"
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;_USRDLL;_ATL_ATTRIBUTES"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1049"
|
||||
AdditionalIncludeDirectories="$(IntDir)"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="true"
|
||||
OutputFile="$(OutDir)/AVSFontConverter.dll"
|
||||
LinkIncremental="2"
|
||||
MergedIDLBaseFileName="_AVSFontConverter.idl"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
ImportLibrary="$(OutDir)/AVSFontConverter.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="Performing registration"
|
||||
CommandLine="regsvr32 /s /c "$(TargetPath)""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="2"
|
||||
UseOfATL="1"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
CommandLine="..\..\..\Redist\VersionControl.exe "$(SolutionDir)\version.h""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
MkTypLibCompatible="false"
|
||||
TargetEnvironment="1"
|
||||
GenerateStublessProxies="true"
|
||||
TypeLibraryName="$(IntDir)/AVSFontConverter.tlb"
|
||||
HeaderFileName="AVSFontConverter.h"
|
||||
DLLDataFileName=""
|
||||
InterfaceIdentifierFileName="AVSFontConverter_i.c"
|
||||
ProxyFileName="AVSFontConverter_p.c"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\AVSImageStudio3\AVSGraphics\Objects\Font\FreeType\"
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;_USRDLL;_ATL_ATTRIBUTES"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1049"
|
||||
AdditionalIncludeDirectories="$(IntDir)"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="true"
|
||||
OutputFile="../../../Redist/AVSOfficeStudio/AVSFontConverter.dll"
|
||||
LinkIncremental="1"
|
||||
MergedIDLBaseFileName="_AVSFontConverter.idl"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(OutDir)$(TargetName).pdb"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
ImportLibrary="$(OutDir)/AVSFontConverter.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="Performing registration"
|
||||
CommandLine="regsvr32 /s /c "$(TargetPath)""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="ReleaseASC|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="2"
|
||||
UseOfATL="1"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
CommandLine="..\..\..\Redist\VersionControl.exe "$(SolutionDir)\version.h""
|
||||
ExcludedFromBuild="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
MkTypLibCompatible="false"
|
||||
TargetEnvironment="1"
|
||||
GenerateStublessProxies="true"
|
||||
TypeLibraryName="$(IntDir)/AVSFontConverter.tlb"
|
||||
HeaderFileName="AVSFontConverter.h"
|
||||
DLLDataFileName=""
|
||||
InterfaceIdentifierFileName="AVSFontConverter_i.c"
|
||||
ProxyFileName="AVSFontConverter_p.c"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\AVSImageStudio3\AVSGraphics\Objects\Font\FreeType\"
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;_USRDLL;_ATL_ATTRIBUTES"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG;ASCBUILD"
|
||||
Culture="1049"
|
||||
AdditionalIncludeDirectories="$(IntDir)"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="true"
|
||||
OutputFile="../../../..\ASC\Redist/ASCOfficeStudio/ASCFontConverter.dll"
|
||||
LinkIncremental="1"
|
||||
MergedIDLBaseFileName="_AVSFontConverter.idl"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(OutDir)$(TargetName).pdb"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
ImportLibrary="$(OutDir)/AVSFontConverter.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="Performing registration"
|
||||
CommandLine="regsvr32 /s /c "$(TargetPath)""
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\AVSFontConverter.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontConverter.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="ReleaseASC|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Consts.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontConverter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Hash.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Hash.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\MemoryUtils.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\StringExt.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\StringExt.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Utils.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\version.h"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="FontFile"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\FontFileBase.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontFileEncodings.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontFileEncodings.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontFileTrueType.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontFileTrueType.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontFileType1.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontFileType1.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontFileType1C.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontFileType1C.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\AVSFontConverter.rc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\AVSFontConverter.rgs"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
9
AVSFontConverter/Consts.h
Normal file
9
AVSFontConverter/Consts.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
const long c_lFromAll = 0xFFFF; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
const long c_lFromTT = 0x0010; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> TrueType <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
const long c_lFromT1 = 0x0020; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> Type 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
const long c_lFromCFF = 0x0040; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> CFF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
const long c_lFlagsGids = 0x0080;
|
||||
|
||||
|
||||
8
AVSFontConverter/FontConverter.cpp
Normal file
8
AVSFontConverter/FontConverter.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// FontConverter.cpp : Implementation of CFontConverter
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "FontConverter.h"
|
||||
|
||||
|
||||
// CFontConverter12
|
||||
|
||||
479
AVSFontConverter/FontConverter.h
Normal file
479
AVSFontConverter/FontConverter.h
Normal file
@ -0,0 +1,479 @@
|
||||
// FontConverter.h : Declaration of the CFontConverter
|
||||
|
||||
#pragma once
|
||||
#include "resource.h" // main symbols
|
||||
|
||||
#include FT_XFREE86_H
|
||||
#include FT_TRUETYPE_TABLES_H
|
||||
#include "FontFileTrueType.h"
|
||||
#include "FontFileType1C.h"
|
||||
#include "FontFileType1.h"
|
||||
#include "Consts.h"
|
||||
|
||||
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
|
||||
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
|
||||
#endif
|
||||
|
||||
// IFontConverter
|
||||
[
|
||||
object,
|
||||
uuid("F92BB671-8B39-4D4F-AC43-D697A20CE0CA"),
|
||||
dual, helpstring("IFontConverter Interface"),
|
||||
pointer_default(unique)
|
||||
]
|
||||
__interface IFontConverter : IDispatch
|
||||
{
|
||||
|
||||
[id(101)] HRESULT ToOTF([in] BSTR bsInFontFile, [in] BSTR pbsFontFileOut, [in, satype("unsigned short")] SAFEARRAY *pUnicode, [in] BSTR bsName, [in] long nFlag );
|
||||
[id(102)] HRESULT ToOTF2([in] BSTR bsInFontFile, [in, satype("unsigned short")] SAFEARRAY *pUnicode, [in] BSTR bsName, [in] long nFlag, [in] long lSrcFaceIndex, [out, satype("BYTE")] SAFEARRAY** ppFontData);
|
||||
|
||||
//----- <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ----------------------------------------------------------------
|
||||
|
||||
[id(10001)] HRESULT SetAdditionalParam([in] BSTR ParamName, [in] VARIANT ParamValue);
|
||||
[id(10002)] HRESULT GetAdditionalParam([in] BSTR ParamName, [out] VARIANT * ParamValue);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// CFontConverter
|
||||
|
||||
[
|
||||
coclass,
|
||||
default(IFontConverter),
|
||||
threading(apartment),
|
||||
vi_progid("AVSFontConverter.FontConverter"),
|
||||
progid("AVSFontConverter.FontConverter.1"),
|
||||
version(1.0),
|
||||
uuid("3B756386-2427-461C-B979-3AB33F2A057E"),
|
||||
helpstring("FontConverter Class")
|
||||
]
|
||||
class ATL_NO_VTABLE CFontConverter : public IFontConverter
|
||||
{
|
||||
public:
|
||||
CFontConverter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
DECLARE_PROTECT_FINAL_CONSTRUCT()
|
||||
|
||||
HRESULT FinalConstruct()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void FinalRelease()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
STDMETHOD(ToOTF)(BSTR bsFontIn, BSTR bsFontOut, SAFEARRAY *pUnicodeArray, BSTR bsName, long nFlag)
|
||||
{
|
||||
FT_Library pLibrary = NULL;
|
||||
if ( FT_Init_FreeType( &pLibrary ) )
|
||||
return S_FALSE;
|
||||
|
||||
FT_Face pFace = NULL;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
HANDLE hFile = CreateFile( (LPCWSTR)bsFontIn, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (INVALID_HANDLE_VALUE == hFile)
|
||||
return NULL; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
DWORD nFileSize = GetFileSize(hFile, NULL);
|
||||
HANDLE hMapFile = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, nFileSize, NULL);
|
||||
if (NULL == hMapFile)
|
||||
{
|
||||
CloseHandle( hFile );
|
||||
return NULL; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
void *pBaseAddress = MapViewOfFile( hMapFile, FILE_MAP_READ, 0, 0, 0 );
|
||||
if ( !pBaseAddress )
|
||||
{
|
||||
CloseHandle( hMapFile );
|
||||
CloseHandle( hFile );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FT_Open_Args oOpenArgs;
|
||||
oOpenArgs.flags = FT_OPEN_MEMORY;
|
||||
oOpenArgs.memory_base = (BYTE*)pBaseAddress;
|
||||
oOpenArgs.memory_size = (FT_Long)nFileSize;
|
||||
|
||||
CFontFileTrueType* pTTF = CFontFileTrueType::LoadFromFile( bsFontIn );
|
||||
FT_Error oerrr;
|
||||
if ( oerrr = FT_Open_Face( pLibrary, &oOpenArgs, 0, &pFace ) )
|
||||
{
|
||||
FT_Done_FreeType( pLibrary );
|
||||
CloseHandle( hMapFile );
|
||||
CloseHandle( hFile );
|
||||
UnmapViewOfFile( pBaseAddress );
|
||||
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
CString sFontFormat( FT_Get_X11_Font_Format( pFace ) );
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool bNeedConvert = false;
|
||||
|
||||
if ( nFlag == c_lFromAll || ( _T("TrueType") == sFontFormat && nFlag & c_lFromTT ) || ( _T("CFF") == sFontFormat && nFlag & c_lFromCFF ) || ( _T("Type 1") == sFontFormat && nFlag & c_lFromT1 ) )
|
||||
bNeedConvert = true;
|
||||
|
||||
bool bIsGids = (c_lFlagsGids & nFlag);
|
||||
|
||||
if ( bNeedConvert )
|
||||
{
|
||||
if ( _T("CFF") == sFontFormat || _T("Type 1") == sFontFormat )
|
||||
{
|
||||
TCharBuffer oCFF;
|
||||
CFontFileType1C *pT1C = NULL;
|
||||
if ( _T("Type 1") == sFontFormat )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Type1 <20> CFF
|
||||
CFontFileType1* pT1 = CFontFileType1::LoadFromFile( bsFontIn );
|
||||
pT1->ToCFF( &CharBufferWrite, &oCFF );
|
||||
delete pT1;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CFF <20> OpenTypeCFF
|
||||
pT1C = CFontFileType1C::LoadFromBuffer( oCFF.sBuffer, oCFF.nLen );
|
||||
}
|
||||
else
|
||||
{
|
||||
// FreeType <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CFF, <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> OpenType(CFF).
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>.
|
||||
pT1C = CFontFileType1C::LoadFromFile( bsFontIn );
|
||||
}
|
||||
|
||||
if ( pT1C )
|
||||
{
|
||||
FILE* pFile = _wfopen( bsFontOut, _T("wb+") );
|
||||
pT1C->ToOpenTypeCFF( &FileWrite, pFile, pFace );
|
||||
::fclose( pFile );
|
||||
}
|
||||
|
||||
delete pT1C;
|
||||
}
|
||||
else if ( _T("TrueType") == sFontFormat && ( pUnicodeArray != NULL || bsName != NULL ) )
|
||||
{
|
||||
CFontFileTrueType* pTTF = CFontFileTrueType::LoadFromFile( bsFontIn );
|
||||
if ( pTTF )
|
||||
{
|
||||
USES_CONVERSION;
|
||||
char *sName = ( NULL == bsName ? NULL : W2A( bsName ) );
|
||||
unsigned char *pUseGlyfs = NULL;
|
||||
long lGlyfsCount = pFace->num_glyphs;
|
||||
|
||||
if ( pUnicodeArray )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> GID
|
||||
LONG lCount = pUnicodeArray->rgsabound[0].cElements;
|
||||
unsigned short* pUnicode = (unsigned short*)pUnicodeArray->pvData;
|
||||
unsigned short* pGIDs = new unsigned short[lCount];
|
||||
int nCMapIndex = 0;
|
||||
|
||||
int nSymbolicIndex = GetSymbolicCmapIndex(pFace);
|
||||
|
||||
if (!bIsGids)
|
||||
{
|
||||
for ( int nIndex = 0; nIndex < lCount; nIndex++ )
|
||||
{
|
||||
pGIDs[nIndex] = SetCMapForCharCode( pFace, pUnicode[nIndex], &nCMapIndex );
|
||||
|
||||
if ((pGIDs[nIndex] == 0) && (-1 != nSymbolicIndex) && (pUnicode[nIndex] < 0xF000))
|
||||
{
|
||||
pGIDs[nIndex] = SetCMapForCharCode( pFace, pUnicode[nIndex] + 0xF000, &nCMapIndex );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(pGIDs, pUnicode, lCount * sizeof(unsigned short));
|
||||
}
|
||||
|
||||
pUseGlyfs = new unsigned char[lGlyfsCount];
|
||||
::memset( pUseGlyfs, 0x00, lGlyfsCount * sizeof(unsigned char) );
|
||||
pUseGlyfs[0] = 1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for ( int nGID = 1; nGID < lGlyfsCount; nGID++ )
|
||||
{
|
||||
if ( 1 != pUseGlyfs[nGID] )
|
||||
{
|
||||
bool bFound = false;
|
||||
for ( int nIndex = 0; nIndex < lCount; nIndex++ )
|
||||
{
|
||||
if ( nGID == pGIDs[nIndex] )
|
||||
{
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (CompositeGlyf), <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (subglyfs)
|
||||
if ( bFound && 0 == FT_Load_Glyph( pFace, nGID, FT_LOAD_NO_SCALE | FT_LOAD_NO_RECURSE ) )
|
||||
{
|
||||
for ( int nSubIndex = 0; nSubIndex < pFace->glyph->num_subglyphs; nSubIndex++ )
|
||||
{
|
||||
FT_Int nSubGID;
|
||||
FT_UInt unFlags;
|
||||
FT_Int nArg1;
|
||||
FT_Int nArg2;
|
||||
FT_Matrix oMatrix;
|
||||
FT_Get_SubGlyph_Info( pFace->glyph, nSubIndex, &nSubGID, &unFlags, &nArg1, &nArg2, &oMatrix );
|
||||
|
||||
if ( nSubGID < lGlyfsCount )
|
||||
pUseGlyfs[nSubGID] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bFound )
|
||||
pUseGlyfs[nGID] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FILE* pFile = _wfopen( bsFontOut, _T("wb+") );
|
||||
pTTF->WriteTTF( &FileWrite, pFile, sName, NULL, pUseGlyfs, lGlyfsCount );
|
||||
::fclose( pFile );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
CopyFile( bsFontIn, bsFontOut, FALSE );
|
||||
}
|
||||
|
||||
FT_Done_Face( pFace );
|
||||
FT_Done_FreeType( pLibrary );
|
||||
|
||||
CloseHandle( hMapFile );
|
||||
CloseHandle( hFile );
|
||||
UnmapViewOfFile( pBaseAddress );
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(ToOTF2)(BSTR bsFontIn, SAFEARRAY *pUnicodeArray, BSTR bsName, long nFlag, long lFaceIndex, SAFEARRAY** ppData)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD> <20><><EFBFBD> <20><>-<2D><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
|
||||
FT_Library pLibrary = NULL;
|
||||
if ( FT_Init_FreeType( &pLibrary ) )
|
||||
return S_FALSE;
|
||||
|
||||
FT_Face pFace = NULL;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
HANDLE hFile = CreateFile( (LPCWSTR)bsFontIn, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (INVALID_HANDLE_VALUE == hFile || NULL == ppData)
|
||||
return NULL; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
DWORD nFileSize = GetFileSize(hFile, NULL);
|
||||
HANDLE hMapFile = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, nFileSize, NULL);
|
||||
if (NULL == hMapFile)
|
||||
{
|
||||
CloseHandle( hFile );
|
||||
return NULL; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
void *pBaseAddress = MapViewOfFile( hMapFile, FILE_MAP_READ, 0, 0, 0 );
|
||||
if ( !pBaseAddress )
|
||||
{
|
||||
CloseHandle( hMapFile );
|
||||
CloseHandle( hFile );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FT_Open_Args oOpenArgs;
|
||||
oOpenArgs.flags = FT_OPEN_MEMORY;
|
||||
oOpenArgs.memory_base = (BYTE*)pBaseAddress;
|
||||
oOpenArgs.memory_size = (FT_Long)nFileSize;
|
||||
|
||||
CFontFileTrueType* pTTF = CFontFileTrueType::LoadFromFile( bsFontIn );
|
||||
FT_Error oerrr;
|
||||
if ( oerrr = FT_Open_Face( pLibrary, &oOpenArgs, lFaceIndex, &pFace ) )
|
||||
{
|
||||
FT_Done_FreeType( pLibrary );
|
||||
CloseHandle( hMapFile );
|
||||
CloseHandle( hFile );
|
||||
UnmapViewOfFile( pBaseAddress );
|
||||
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
CString sFontFormat( FT_Get_X11_Font_Format( pFace ) );
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool bNeedConvert = false;
|
||||
|
||||
if ( nFlag == c_lFromAll || ( _T("TrueType") == sFontFormat && nFlag & c_lFromTT ) || ( _T("CFF") == sFontFormat && nFlag & c_lFromCFF ) || ( _T("Type 1") == sFontFormat && nFlag & c_lFromT1 ) )
|
||||
bNeedConvert = true;
|
||||
|
||||
bool bIsGids = (c_lFlagsGids & nFlag);
|
||||
|
||||
TCharBuffer* pCharBuffer = NULL;
|
||||
|
||||
if ( bNeedConvert )
|
||||
{
|
||||
pCharBuffer = new TCharBuffer(100000); // ~100Kb
|
||||
if ( _T("CFF") == sFontFormat || _T("Type 1") == sFontFormat )
|
||||
{
|
||||
TCharBuffer oCFF;
|
||||
CFontFileType1C *pT1C = NULL;
|
||||
if ( _T("Type 1") == sFontFormat )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Type1 <20> CFF
|
||||
CFontFileType1* pT1 = CFontFileType1::LoadFromFile( bsFontIn );
|
||||
pT1->ToCFF( &CharBufferWrite, &oCFF );
|
||||
delete pT1;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CFF <20> OpenTypeCFF
|
||||
pT1C = CFontFileType1C::LoadFromBuffer( oCFF.sBuffer, oCFF.nLen );
|
||||
}
|
||||
else
|
||||
{
|
||||
// FreeType <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CFF, <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> OpenType(CFF).
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>.
|
||||
pT1C = CFontFileType1C::LoadFromFile( bsFontIn );
|
||||
}
|
||||
|
||||
if ( pT1C )
|
||||
{
|
||||
pT1C->ToOpenTypeCFF( &CharBufferWrite, pCharBuffer, pFace );
|
||||
}
|
||||
|
||||
delete pT1C;
|
||||
}
|
||||
else if ( _T("TrueType") == sFontFormat && ( pUnicodeArray != NULL || bsName != NULL ) )
|
||||
{
|
||||
CFontFileTrueType* pTTF = CFontFileTrueType::LoadFromFile( bsFontIn );
|
||||
if ( pTTF )
|
||||
{
|
||||
USES_CONVERSION;
|
||||
char *sName = ( NULL == bsName ? NULL : W2A( bsName ) );
|
||||
unsigned char *pUseGlyfs = NULL;
|
||||
long lGlyfsCount = pFace->num_glyphs;
|
||||
|
||||
if ( pUnicodeArray )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> GID
|
||||
LONG lCount = pUnicodeArray->rgsabound[0].cElements;
|
||||
unsigned short* pUnicode = (unsigned short*)pUnicodeArray->pvData;
|
||||
unsigned short* pGIDs = new unsigned short[lCount];
|
||||
int nCMapIndex = 0;
|
||||
|
||||
int nSymbolicIndex = GetSymbolicCmapIndex(pFace);
|
||||
|
||||
if (!bIsGids)
|
||||
{
|
||||
for ( int nIndex = 0; nIndex < lCount; nIndex++ )
|
||||
{
|
||||
pGIDs[nIndex] = SetCMapForCharCode( pFace, pUnicode[nIndex], &nCMapIndex );
|
||||
|
||||
if ((pGIDs[nIndex] == 0) && (-1 != nSymbolicIndex) && (pUnicode[nIndex] < 0xF000))
|
||||
{
|
||||
pGIDs[nIndex] = SetCMapForCharCode( pFace, pUnicode[nIndex] + 0xF000, &nCMapIndex );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(pGIDs, pUnicode, lCount * sizeof(unsigned short));
|
||||
}
|
||||
|
||||
pUseGlyfs = new unsigned char[lGlyfsCount];
|
||||
::memset( pUseGlyfs, 0x00, lGlyfsCount * sizeof(unsigned char) );
|
||||
pUseGlyfs[0] = 1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for ( int nGID = 1; nGID < lGlyfsCount; nGID++ )
|
||||
{
|
||||
if ( 1 != pUseGlyfs[nGID] )
|
||||
{
|
||||
bool bFound = false;
|
||||
for ( int nIndex = 0; nIndex < lCount; nIndex++ )
|
||||
{
|
||||
if ( nGID == pGIDs[nIndex] )
|
||||
{
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (CompositeGlyf), <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (subglyfs)
|
||||
if ( bFound && 0 == FT_Load_Glyph( pFace, nGID, FT_LOAD_NO_SCALE | FT_LOAD_NO_RECURSE ) )
|
||||
{
|
||||
for ( int nSubIndex = 0; nSubIndex < pFace->glyph->num_subglyphs; nSubIndex++ )
|
||||
{
|
||||
FT_Int nSubGID;
|
||||
FT_UInt unFlags;
|
||||
FT_Int nArg1;
|
||||
FT_Int nArg2;
|
||||
FT_Matrix oMatrix;
|
||||
FT_Get_SubGlyph_Info( pFace->glyph, nSubIndex, &nSubGID, &unFlags, &nArg1, &nArg2, &oMatrix );
|
||||
|
||||
if ( nSubGID < lGlyfsCount )
|
||||
pUseGlyfs[nSubGID] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bFound )
|
||||
pUseGlyfs[nGID] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pTTF->WriteTTF( &CharBufferWrite, pCharBuffer, sName, NULL, pUseGlyfs, lGlyfsCount );
|
||||
}
|
||||
}
|
||||
|
||||
LONG nSizeFont = pCharBuffer->nLen;
|
||||
|
||||
SAFEARRAYBOUND rgsab;
|
||||
rgsab.lLbound = 0;
|
||||
rgsab.cElements = nSizeFont;
|
||||
|
||||
SAFEARRAY* pArray = SafeArrayCreate(VT_UI1, 1, &rgsab);
|
||||
memcpy(pArray->pvData, pCharBuffer->sBuffer, nSizeFont);
|
||||
|
||||
RELEASEOBJECT(pCharBuffer);
|
||||
|
||||
*ppData = pArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
SAFEARRAYBOUND rgsab;
|
||||
rgsab.lLbound = 0;
|
||||
rgsab.cElements = nFileSize;
|
||||
|
||||
SAFEARRAY* pArray = SafeArrayCreate(VT_UI1, 1, &rgsab);
|
||||
memcpy(pArray->pvData, pBaseAddress, nFileSize);
|
||||
|
||||
*ppData = pArray;
|
||||
}
|
||||
|
||||
FT_Done_Face( pFace );
|
||||
FT_Done_FreeType( pLibrary );
|
||||
|
||||
CloseHandle( hMapFile );
|
||||
CloseHandle( hFile );
|
||||
UnmapViewOfFile( pBaseAddress );
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(SetAdditionalParam)(BSTR bsParamName, VARIANT vParamValue)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(GetAdditionalParam)(BSTR bsParamName, VARIANT *pvParamValue)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
231
AVSFontConverter/FontFileBase.h
Normal file
231
AVSFontConverter/FontFileBase.h
Normal file
@ -0,0 +1,231 @@
|
||||
#ifndef _FONT_FILE_BASE_H
|
||||
#define _FONT_FILE_BASE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "MemoryUtils.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
typedef void (*FontFileOutputFunc)(void *pStream, char *sData, int nLen);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// CFontFileBase
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
class CFontFileBase
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~CFontFileBase()
|
||||
{
|
||||
if ( m_bFreeFileData )
|
||||
MemUtilsFree( m_sFileData );
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
CFontFileBase(char *sFile, int nLen, BOOL bFreeFileData)
|
||||
{
|
||||
m_sFileData = m_sFile = (unsigned char *)sFile;
|
||||
m_nLen = nLen;
|
||||
m_bFreeFileData = bFreeFileData;
|
||||
m_nPos = 0;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_nPos = 0;
|
||||
}
|
||||
static char *ReadFile(wchar_t *wsFileName, int *pnFileLen)
|
||||
{
|
||||
FILE *pFile;
|
||||
|
||||
if ( !( pFile = _wfopen( wsFileName, _T("rb") ) ) )
|
||||
return NULL;
|
||||
|
||||
fseek( pFile, 0, SEEK_END );
|
||||
int nLen = (int)ftell( pFile );
|
||||
fseek( pFile, 0, SEEK_SET );
|
||||
char *sBuffer = (char *)MemUtilsMalloc( nLen );
|
||||
if ( (int)fread( sBuffer, 1, nLen, pFile) != nLen )
|
||||
{
|
||||
MemUtilsFree( sBuffer );
|
||||
fclose( pFile );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fclose( pFile );
|
||||
*pnFileLen = nLen;
|
||||
return sBuffer;
|
||||
}
|
||||
|
||||
// S = signed / U = unsigned
|
||||
// 8/16/32/Var = word length, in bytes
|
||||
// BE = big endian
|
||||
int GetS8 (int nPos, BOOL *pbSuccess)
|
||||
{
|
||||
*pbSuccess = TRUE;
|
||||
|
||||
if ( nPos < 0 || nPos >= m_nLen )
|
||||
{
|
||||
*pbSuccess = FALSE;
|
||||
return 0;
|
||||
}
|
||||
int nRes = m_sFile[ nPos ];
|
||||
if ( nRes & 0x80 )
|
||||
nRes |= ~0xff;
|
||||
return nRes;
|
||||
}
|
||||
|
||||
int GetU8 (int nPos, BOOL *pbSuccess)
|
||||
{
|
||||
*pbSuccess = TRUE;
|
||||
if ( nPos < 0 || nPos >= m_nLen )
|
||||
{
|
||||
*pbSuccess = FALSE;
|
||||
return 0;
|
||||
}
|
||||
return m_sFile[ nPos ];
|
||||
}
|
||||
|
||||
int GetS16BE (int nPos, BOOL *pbSuccess)
|
||||
{
|
||||
*pbSuccess = TRUE;
|
||||
|
||||
if ( nPos < 0 || nPos + 1 >= m_nLen )
|
||||
{
|
||||
*pbSuccess = FALSE;
|
||||
return 0;
|
||||
}
|
||||
int nRes = m_sFile[nPos];
|
||||
nRes = (nRes << 8) + m_sFile[ nPos + 1 ];
|
||||
if ( nRes & 0x8000 )
|
||||
nRes |= ~0xffff;
|
||||
return nRes;
|
||||
}
|
||||
|
||||
int GetU16BE (int nPos, BOOL *pbSuccess)
|
||||
{
|
||||
*pbSuccess = TRUE;
|
||||
|
||||
if ( nPos < 0 || nPos + 1 >= m_nLen)
|
||||
{
|
||||
*pbSuccess = FALSE;
|
||||
return 0;
|
||||
}
|
||||
int nRes = m_sFile[ nPos ];
|
||||
nRes = (nRes << 8) + m_sFile[ nPos + 1 ];
|
||||
return nRes;
|
||||
}
|
||||
|
||||
int GetS32BE (int nPos, BOOL *pbSuccess)
|
||||
{
|
||||
*pbSuccess = TRUE;
|
||||
|
||||
if ( nPos < 0 || nPos + 3 >= m_nLen )
|
||||
{
|
||||
*pbSuccess = FALSE;
|
||||
return 0;
|
||||
}
|
||||
int nRes = m_sFile[ nPos ];
|
||||
nRes = (nRes << 8) + m_sFile[nPos + 1];
|
||||
nRes = (nRes << 8) + m_sFile[nPos + 2];
|
||||
nRes = (nRes << 8) + m_sFile[nPos + 3];
|
||||
if ( nRes & 0x80000000 )
|
||||
nRes |= ~0xffffffff;
|
||||
|
||||
return nRes;
|
||||
}
|
||||
|
||||
unsigned int GetU32BE (int nPos, BOOL *pbSuccess)
|
||||
{
|
||||
*pbSuccess = TRUE;
|
||||
|
||||
if ( nPos < 0 || nPos + 3 >= m_nLen )
|
||||
{
|
||||
*pbSuccess = FALSE;
|
||||
return 0;
|
||||
}
|
||||
unsigned int nRes = m_sFile[nPos];
|
||||
nRes = (nRes << 8) + m_sFile[nPos + 1];
|
||||
nRes = (nRes << 8) + m_sFile[nPos + 2];
|
||||
nRes = (nRes << 8) + m_sFile[nPos + 3];
|
||||
return nRes;
|
||||
}
|
||||
unsigned int GetU32LE (int nPos, BOOL *pbSuccess)
|
||||
{
|
||||
*pbSuccess = TRUE;
|
||||
|
||||
if ( nPos < 0 || nPos + 3 >= m_nLen )
|
||||
{
|
||||
*pbSuccess = FALSE;
|
||||
return 0;
|
||||
}
|
||||
unsigned int nRes = m_sFile[nPos + 3];
|
||||
nRes = (nRes << 8) + m_sFile[nPos + 2];
|
||||
nRes = (nRes << 8) + m_sFile[nPos + 1];
|
||||
nRes = (nRes << 8) + m_sFile[nPos + 0];
|
||||
return nRes;
|
||||
}
|
||||
unsigned int GetUVarBE(int nPos, int nSize, BOOL *pbSuccess)
|
||||
{
|
||||
*pbSuccess = TRUE;
|
||||
|
||||
if ( nPos < 0 || nPos + nSize > m_nLen )
|
||||
{
|
||||
*pbSuccess = FALSE;
|
||||
return 0;
|
||||
}
|
||||
unsigned int nRes = 0;
|
||||
for ( int nIndex = 0; nIndex < nSize; ++nIndex )
|
||||
nRes = (nRes << 8) + m_sFile[nPos + nIndex];
|
||||
|
||||
return nRes;
|
||||
}
|
||||
|
||||
BOOL CheckRegion(int nPos, int nSize)
|
||||
{
|
||||
return (nPos >= 0 && nPos + nSize >= nPos && nPos + nSize <= m_nLen);
|
||||
}
|
||||
int ReadS8 (BOOL *pbSuccess)
|
||||
{
|
||||
return GetS8( m_nPos++, pbSuccess );
|
||||
}
|
||||
int ReadU8 (BOOL *pbSuccess)
|
||||
{
|
||||
return GetU8( m_nPos++, pbSuccess );
|
||||
}
|
||||
unsigned int ReadU32BE(BOOL *pbSuccess)
|
||||
{
|
||||
unsigned int unResult = GetU32BE( m_nPos, pbSuccess );
|
||||
m_nPos += 4;
|
||||
return unResult;
|
||||
}
|
||||
unsigned int ReadU32LE(BOOL *pbSuccess)
|
||||
{
|
||||
unsigned int unResult = GetU32LE( m_nPos, pbSuccess );
|
||||
m_nPos += 4;
|
||||
return unResult;
|
||||
}
|
||||
int Read(void* pDestBuffer, int nSize)
|
||||
{
|
||||
if ( m_nPos + nSize >= m_nLen )
|
||||
nSize = m_nLen - m_nPos - 1;
|
||||
|
||||
memcpy( pDestBuffer, (m_sFile + m_nPos), nSize );
|
||||
m_nPos += nSize;
|
||||
|
||||
return nSize;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
unsigned char *m_sFileData;
|
||||
unsigned char *m_sFile;
|
||||
int m_nLen;
|
||||
BOOL m_bFreeFileData;
|
||||
int m_nPos;
|
||||
|
||||
};
|
||||
|
||||
#endif /* _FONT_FILE_BASE_H */
|
||||
5746
AVSFontConverter/FontFileEncodings.cpp
Normal file
5746
AVSFontConverter/FontFileEncodings.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1080
AVSFontConverter/FontFileEncodings.h
Normal file
1080
AVSFontConverter/FontFileEncodings.h
Normal file
File diff suppressed because it is too large
Load Diff
2109
AVSFontConverter/FontFileTrueType.cpp
Normal file
2109
AVSFontConverter/FontFileTrueType.cpp
Normal file
File diff suppressed because it is too large
Load Diff
243
AVSFontConverter/FontFileTrueType.h
Normal file
243
AVSFontConverter/FontFileTrueType.h
Normal file
@ -0,0 +1,243 @@
|
||||
#ifndef _FONT_FILE_TRUETYPE_H
|
||||
#define _FONT_FILE_TRUETYPE_H
|
||||
|
||||
#include "FontFileBase.h"
|
||||
|
||||
class StringExt;
|
||||
class CHash;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
#define ttcfTag 0x74746366
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
struct TrueTypeTable
|
||||
{
|
||||
unsigned int unTag;
|
||||
unsigned int unChecksum;
|
||||
int nOffset;
|
||||
int nOrigOffset;
|
||||
int nLen;
|
||||
};
|
||||
|
||||
struct TrueTypeCmap
|
||||
{
|
||||
int nPlatform;
|
||||
int nEncoding;
|
||||
int nOffset;
|
||||
int nLen;
|
||||
int nFormat;
|
||||
};
|
||||
|
||||
struct TrueTypeLoca
|
||||
{
|
||||
int nIndex;
|
||||
int nOrigOffset;
|
||||
int nNewOffset;
|
||||
int nLen;
|
||||
};
|
||||
|
||||
#define cffTag 0x43464620
|
||||
#define maxpTag 0x6d617870
|
||||
#define cmapTag 0x636d6170
|
||||
#define glyfTag 0x676c7966
|
||||
#define headTag 0x68656164
|
||||
#define hheaTag 0x68686561
|
||||
#define hmtxTag 0x686d7478
|
||||
#define locaTag 0x6c6f6361
|
||||
#define nameTag 0x6e616d65
|
||||
#define os2Tag 0x4f532f32
|
||||
#define postTag 0x706f7374
|
||||
|
||||
#define cvtTag 0x63767420
|
||||
#define fpgmTag 0x6670676d
|
||||
#define prepTag 0x70726570
|
||||
|
||||
static int CompareTrueTypeLocaOffset(const void *pL1, const void *pL2)
|
||||
{
|
||||
TrueTypeLoca *pLoca1 = (TrueTypeLoca *)pL1;
|
||||
TrueTypeLoca *pLoca2 = (TrueTypeLoca *)pL2;
|
||||
|
||||
if ( pLoca1->nOrigOffset == pLoca2->nOrigOffset )
|
||||
return pLoca1->nIndex - pLoca2->nIndex;
|
||||
|
||||
return pLoca1->nOrigOffset - pLoca2->nOrigOffset;
|
||||
}
|
||||
|
||||
static int CompareTrueTypeLocaIndex(const void *pL1, const void *pL2)
|
||||
{
|
||||
TrueTypeLoca *pLoca1 = (TrueTypeLoca *)pL1;
|
||||
TrueTypeLoca *pLoca2 = (TrueTypeLoca *)pL2;
|
||||
|
||||
return pLoca1->nIndex - pLoca2->nIndex;
|
||||
}
|
||||
|
||||
static int CompareTrueTypeTableTag(const void *pTab1, const void *pTab2)
|
||||
{
|
||||
TrueTypeTable *pTable1 = (TrueTypeTable *)pTab1;
|
||||
TrueTypeTable *pTable2 = (TrueTypeTable *)pTab2;
|
||||
|
||||
return (int)pTable1->unTag - (int)pTable2->unTag;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
struct T42Table
|
||||
{
|
||||
char *sTag; // 4-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BOOL bRequired; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TrueType?
|
||||
};
|
||||
|
||||
// TrueType tables to be embedded in Type 42 fonts.
|
||||
// NB: the table names must be in alphabetical order here.
|
||||
#define nT42Tables 11
|
||||
static T42Table t42Tables[nT42Tables] =
|
||||
{
|
||||
{ "cvt ", TRUE },
|
||||
{ "fpgm", TRUE },
|
||||
{ "glyf", TRUE },
|
||||
{ "head", TRUE },
|
||||
{ "hhea", TRUE },
|
||||
{ "hmtx", TRUE },
|
||||
{ "loca", TRUE },
|
||||
{ "maxp", TRUE },
|
||||
{ "prep", TRUE },
|
||||
{ "vhea", FALSE },
|
||||
{ "vmtx", FALSE }
|
||||
};
|
||||
#define t42HeadTable 3
|
||||
#define t42LocaTable 6
|
||||
#define t42GlyfTable 2
|
||||
#define t42VheaTable 9
|
||||
#define t42VmtxTable 10
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// CFontFileTrueType
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
class CFontFileTrueType: public CFontFileBase
|
||||
{
|
||||
public:
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TTF <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
static CFontFileTrueType *LoadFromBuffer(char *sBuffer, int lenA);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TTF <20><> <20><><EFBFBD><EFBFBD><EFBFBD>.
|
||||
static CFontFileTrueType *LoadFromFile(wchar_t *wsFileName);
|
||||
|
||||
virtual ~CFontFileTrueType();
|
||||
|
||||
// TRUE, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> OpenType <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CFF.
|
||||
// FALSE,<2C><><EFBFBD><EFBFBD> <20><><EFBFBD> TrueType <20><><EFBFBD><EFBFBD> ( <20><><EFBFBD> OpenType <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TrueType).
|
||||
BOOL IsOpenTypeCFF()
|
||||
{
|
||||
return m_bOpenTypeCFF;
|
||||
}
|
||||
|
||||
int GetCmapsCount();
|
||||
|
||||
int GetCmapPlatform(int nIndex);
|
||||
|
||||
int GetCmapEncoding(int nIndex);
|
||||
|
||||
int FindCmap(int nPlatform, int nEncoding);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GID, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <nChar> <20> <nIndex><3E><><EFBFBD> CMap.
|
||||
unsigned short MapCodeToGID(int nCMapIndex, int nChar);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GID, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <sName> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> post. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0,
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> post <20><><EFBFBD>.
|
||||
int MapNameToGID(char *sName);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> CIDs <20> GIDs, <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// CIDs <20> *<pnCIDs>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> CID <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>( OpenType CFF )
|
||||
unsigned short *GetCIDToGIDMap(int *pnCIDs);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>( <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> True Type):
|
||||
|
||||
// * 4: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> OS/2 <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// * 3: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// * 2: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// * 1: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// * 0: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int GetEmbeddingRestrictions();
|
||||
|
||||
// Convert to a Type 42 font, suitable for embedding in a PostScript
|
||||
// file. <psName> will be used as the PostScript font name (so we
|
||||
// don't need to depend on the 'name' table in the font). The
|
||||
// <encoding> array specifies the mapping from char codes to names.
|
||||
// If <encoding> is NULL, the encoding is unknown or undefined. The
|
||||
// <codeToGID> array specifies the mapping from char codes to GIDs.
|
||||
// (Not useful for OpenType CFF fonts.)
|
||||
void ToType42(char *sPSName, char **ppEncoding, unsigned short *pCodeToGID, FontFileOutputFunc pOutputFunc, void *pOutputStream );
|
||||
|
||||
// Convert to a Type 1 font, suitable for embedding in a PostScript
|
||||
// file. This is only useful with 8-bit fonts. If <newEncoding> is
|
||||
// not NULL, it will be used in place of the encoding in the Type 1C
|
||||
// font. If <ascii> is true the eexec section will be hex-encoded,
|
||||
// otherwise it will be left as binary data. If <psName> is
|
||||
// non-NULL, it will be used as the PostScript font name. (Only
|
||||
// useful for OpenType CFF fonts.)
|
||||
void ToType1(char *sPSName, char **ppNewEncoding, BOOL bASKII, FontFileOutputFunc pOutputFunc, void *pOutputStream );
|
||||
|
||||
// Convert to a Type 2 CIDFont, suitable for embedding in a
|
||||
// PostScript file. <psName> will be used as the PostScript font
|
||||
// name (so we don't need to depend on the 'name' table in the
|
||||
// font). The <cidMap> array maps CIDs to GIDs; it has <nCIDs>
|
||||
// entries. (Not useful for OpenType CFF fonts.)
|
||||
void ToCIDType2(char *sPSName, unsigned short *pCIDMap, int nCIDCount, BOOL bNeedVerticalMetrics, FontFileOutputFunc pOutputFunc, void *pOutputStream);
|
||||
|
||||
// Convert to a Type 0 CIDFont, suitable for embedding in a
|
||||
// PostScript file. <psName> will be used as the PostScript font
|
||||
// name. (Only useful for OpenType CFF fonts.)
|
||||
void ToCIDType0(char *sPSName, FontFileOutputFunc pOutputFunc, void *pOutputStream);
|
||||
|
||||
// Convert to a Type 0 (but non-CID) composite font, suitable for
|
||||
// embedding in a PostScript file. <psName> will be used as the
|
||||
// PostScript font name (so we don't need to depend on the 'name'
|
||||
// table in the font). The <cidMap> array maps CIDs to GIDs; it has
|
||||
// <nCIDs> entries. (Not useful for OpenType CFF fonts.)
|
||||
void ToType0(char *sPSName, unsigned short *pCIDMap, int nCIDCount, BOOL bNeedVerticalMetrics, FontFileOutputFunc pOutputFunc, void *pOutputStream);
|
||||
|
||||
// Convert to a Type 0 (but non-CID) composite font, suitable for
|
||||
// embedding in a PostScript file. <psName> will be used as the
|
||||
// PostScript font name. (Only useful for OpenType CFF fonts.)
|
||||
void ToType0(char *sPSName, FontFileOutputFunc pOutputFunc, void *pOutputStream);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TrueTypeFont File, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <sName>, <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 'name'. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <pCodeToGID>, <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 'cmap'.
|
||||
void WriteTTF(FontFileOutputFunc pOutputFunc, void *pOutputStream, char *sName = NULL, unsigned short *pCodeToGID = NULL, unsigned char *pUseGlyfs = NULL, long lGlyfsCount = 0) ;
|
||||
|
||||
private:
|
||||
|
||||
CFontFileTrueType(char *sFileName, int nLen, BOOL bFreeFileData);
|
||||
|
||||
void ConvertEncoding (char **ppEncoding, FontFileOutputFunc pOutputFunc, void *pOutputStream);
|
||||
void ConvertCharStrings(char **ppEncoding, unsigned short *pnCodeToGID, FontFileOutputFunc pOutputFunc, void *pOutputStream);
|
||||
void ConvertSfnts (FontFileOutputFunc pOutputFunc, void *pOutputStream, StringExt *seName, BOOL bNeedVerticalMetrics);
|
||||
void DumpString(unsigned char *sString, int nLength, FontFileOutputFunc pOutputFunc, void *pOutputStream);
|
||||
unsigned int ComputeTableChecksum(unsigned char *sData, int nLength);
|
||||
void Parse();
|
||||
void ReadPostTable();
|
||||
int SeekTable(char *sTag);
|
||||
|
||||
private:
|
||||
|
||||
TrueTypeTable *m_pTables;
|
||||
int m_nTablesCount;
|
||||
TrueTypeCmap *m_pCMaps;
|
||||
int m_nCMapsCount;
|
||||
int m_nGlyphs;
|
||||
int m_nLocaFormat;
|
||||
int m_arrBBox[4];
|
||||
CHash *m_pNameToGID;
|
||||
BOOL m_bOpenTypeCFF;
|
||||
|
||||
BOOL m_bSuccess;
|
||||
};
|
||||
|
||||
#endif /* _FONT_FILE_TRUETYPE_H */
|
||||
1253
AVSFontConverter/FontFileType1.cpp
Normal file
1253
AVSFontConverter/FontFileType1.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user