Commit d6cd7ad4 authored by Sergey.Kirillov's avatar Sergey.Kirillov Committed by Alexander Trofimov

git-svn-id:...

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@52209 954022d7-b5bf-4e40-9824-e11837661b57
parent 48f2b625
// 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") ];
\ No newline at end of file
// 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
HKCR
{
NoRemove AppID
{
'%APPID%' = s 'AVSEBOOKWriter'
'AVSEBOOKWriter.DLL'
{
val AppID = s '%APPID%'
}
}
}
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
<?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 &quot;$(TargetPath)&quot;"
/>
</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 &quot;$(TargetPath)&quot;&#x0D;&#x0A;copy &quot;$(TargetPath)&quot; &quot;$(ProjectDir)..\..\..\Redist\AVSOfficeStudio&quot;&#x0D;&#x0A;"
/>
</Configuration>
<Configuration
Name="ReleaseASC|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="2"
UseOfATL="1"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
CommandLine="..\..\..\Redist\VersionControl.exe $(ProjectDir)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)/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;ASCBUILD"
Culture="1049"
AdditionalIncludeDirectories="$(IntDir)"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
IgnoreImportLibrary="true"
OutputFile="..\..\..\..\..\ASC\Redist\AVSOfficeStudio\ASCEBOOKWriter.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 &quot;$(TargetPath)&quot;&#x0D;&#x0A;copy &quot;$(TargetPath)&quot; &quot;$(ProjectDir)..\..\..\..\ASC\Redist\ASCOfficeStudio&quot;&#x0D;&#x0A;"
/>
</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=".\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=".\EBOOKWriter.h"
>
</File>
<File
RelativePath=".\Resource.h"
>
</File>
<File
RelativePath=".\stdafx.h"
>
</File>
<File
RelativePath=".\TableDetector.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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
<FileConfiguration
Name="ReleaseASC|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>
#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;
};
#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("&amp;"));
strValue.Replace(_T("'"), _T("&apos;"));
strValue.Replace(_T("<"), _T("&lt;"));
strValue.Replace(_T(">"), _T("&gt;"));
strValue.Replace(_T("\""), _T("&quot;"));
}
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)
{
//
++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)
{
//
++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;
}
/*========================================================================================================*/
}
\ No newline at end of file
#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)
{
// ...
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();
}
}
#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)
{
//
Grow();
}
m_lCurrentIndex = m_lCountFonts;
++m_lCountFonts;
m_pFonts[m_lCurrentIndex] = *pFont;
// ...
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)
{
//
Grow();
}
m_lCurrentIndex = m_lCountFonts;
++m_lCountFonts;
m_pFonts[m_lCurrentIndex] = *pFont;
// ...
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)
{
// , 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)
{
//
::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;
}
};
}
\ No newline at end of file
#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;
};
}
\ No newline at end of file
#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"&amp;";
static _bstr_t g_bstr_apos = L"&apos;";
static _bstr_t g_bstr_lt = L"&lt;";
static _bstr_t g_bstr_qt = L"&gt;";
static _bstr_t g_bstr_quot = L"\"";
static _bstr_t g_bstr_mdash = L"&mdash;";
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)
{
//
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)
{
//
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);
}
};
}
\ No newline at end of file
//
// 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;
}
}
#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))
{}
};
}
\ No newline at end of file
//
//
//////////////////////////////////////////////////////////////////////
#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)
#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
\ No newline at end of file
#pragma once
#include "..\stdafx.h"
#include "StringWriter.h"
#include "Structures.h"
#include "Matrix.h"
namespace NSFontManager
{
const double c_dInchToMM = 25.4;
const double c_dPixToMM = 25.4 / 72.0;
const double c_dPtToMM = 25.4 / 72.0;
const double c_dMMToPt = 72.0 / 25.4;
const double c_dDpi = 72.0;
class CFontProperties
{
public:
CString m_strFamilyName;
CString m_strPANOSE;
LONG m_lStyle;
CAtlArray<DWORD> m_arSignature;
bool m_bIsFixedWidth;
LONG m_lAvgWidth;
public:
CFontProperties()
{
m_strFamilyName = _T("");
m_strPANOSE = _T("");
m_lStyle = 0;
m_arSignature.RemoveAll();
m_bIsFixedWidth = false;
m_lAvgWidth = -1;
}
CFontProperties(const CFontProperties& oSrc)
{
*this = oSrc;
}
CFontProperties& operator=(const CFontProperties& oSrc)
{
m_strFamilyName = oSrc.m_strFamilyName;
m_strPANOSE = oSrc.m_strPANOSE;
m_lStyle = oSrc.m_lStyle;
m_arSignature.Copy(oSrc.m_arSignature);
m_bIsFixedWidth = oSrc.m_bIsFixedWidth;
m_lAvgWidth = oSrc.m_lAvgWidth;
return *this;
}
~CFontProperties()
{
}
};
class CFontAdvanced
{
public:
NSStructures::CFont m_oFont;
// font metrics
double m_dAscent;
double m_dDescent;
double m_dLineSpacing;
double m_dEmHeight;
double m_dBaselineOffsetDOCX;
double m_dBaselineOffsetHTML;
double m_dLineSpacingMM;
double m_dSpaceWidthMM;
// font params
CFontProperties m_oProperties;
public:
CFontAdvanced(): m_oProperties()
{
m_oFont.SetDefaultParams();
m_dAscent = 0;
m_dDescent = 0;
m_dLineSpacing = 0;
m_dEmHeight = 0;
m_dBaselineOffsetDOCX = 0;
m_dBaselineOffsetHTML = 0;
m_dSpaceWidthMM = 0;
}
CFontAdvanced(const CFontAdvanced& oSrc)
{
*this = oSrc;
}
CFontAdvanced& operator=(const CFontAdvanced& oSrc)
{
m_oFont = oSrc.m_oFont;
m_dAscent = oSrc.m_dAscent;
m_dDescent = oSrc.m_dDescent;
m_dLineSpacing = oSrc.m_dLineSpacing;
m_dEmHeight = oSrc.m_dEmHeight;
m_dLineSpacingMM = oSrc.m_dLineSpacingMM;
m_dBaselineOffsetDOCX = oSrc.m_dBaselineOffsetDOCX;
m_dBaselineOffsetHTML = oSrc.m_dBaselineOffsetHTML;
m_dSpaceWidthMM = oSrc.m_dSpaceWidthMM;
m_oProperties = oSrc.m_oProperties;
return *this;
}
};
class CFontPickUp
{
public:
CFontAdvanced m_oFont;
BYTE m_lRangeNum;
BYTE m_lRange;
CString m_strPickFont;
LONG m_lPickStyle;
public:
CFontPickUp() : m_oFont()
{
m_lRangeNum = 0xFF;
m_lRange = 0xFF;
m_strPickFont = _T("");
m_lPickStyle = 0;
}
CFontPickUp(const CFontPickUp& oSrc)
{
*this = oSrc;
}
CFontPickUp& operator=(const CFontPickUp& oSrc)
{
m_oFont = oSrc.m_oFont;
m_lRange = oSrc.m_lRange;
m_lRangeNum = oSrc.m_lRangeNum;
m_strPickFont = oSrc.m_strPickFont;
m_lPickStyle = oSrc.m_lPickStyle;
return *this;
}
};
class CFontManagerBase
{
public:
enum MeasureType
{
MeasureTypeGlyph = 0,
MeasureTypePosition = 1
};
protected:
AVSGraphics::IAVSWinFonts* m_pWinFonts;
AVSGraphics::IAVSFontManager* m_pManager;
CString m_strDefaultFont;
public:
CFontAdvanced m_oFont;
//
BYTE m_pRanges[0xFFFF];
BYTE m_pRangesNums[0xFFFF];
BYTE m_mapUnicode[0xFFFF];
CAtlMap<CString, CFontProperties> m_mapFontPathToProperties;
CFontProperties* m_pCurrentProperties;
CAtlList<CFontPickUp> m_arListPicUps;
CString m_strCurrentPickFont;
LONG m_lCurrentPictFontStyle;
bool m_bIsUseFontWidth;
public:
CFontManagerBase() : m_oFont(), m_mapFontPathToProperties()
{
m_pManager = NULL;
CoCreateInstance(AVSGraphics::CLSID_CAVSFontManager, NULL, CLSCTX_ALL, AVSGraphics::IID_IAVSFontManager, (void**)&m_pManager);
m_pManager->Initialize(L"");
SetDefaultFont(_T("Arial"));
ClearPickUps();
InitializeRanges();
InitializeUnicodeMap();
ClearPickUps();
m_pCurrentProperties = NULL;
m_bIsUseFontWidth = false;
}
virtual ~CFontManagerBase()
{
RELEASEINTERFACE(m_pManager);
}
AVSINLINE void ClearPickUps()
{
m_arListPicUps.RemoveAll();
m_strCurrentPickFont = _T("");
m_lCurrentPictFontStyle = 0;
}
public:
AVSINLINE void SetDefaultFont(const CString& strName)
{
m_strDefaultFont = strName;
BSTR bsDefault = m_strDefaultFont.AllocSysString();
m_pManager->SetDefaultFont(bsDefault);
SysFreeString(bsDefault);
}
AVSINLINE CString GetDefaultFont()
{
return m_strDefaultFont;
}
virtual void LoadFont(long lFaceIndex = 0, bool bIsNeedAddToMap = true)
{
}
AVSINLINE void LoadCurrentFont(long lFaceIndex = 0)
{
if (_T("") == m_oFont.m_oFont.Path)
{
LoadFontByName(m_oFont.m_oFont.Name, m_oFont.m_oFont.Size, m_oFont.m_oFont.GetStyle());
}
else
{
LoadFontByFile(m_oFont.m_oFont.Path, m_oFont.m_oFont.Size, lFaceIndex);
m_oFont.m_oFont.SetStyle(m_oFont.m_oProperties.m_lStyle);
}
}
void LoadFontByName(CString& strName, const double& dSize, const LONG& lStyle)
{
BSTR bsName = strName.AllocSysString();
m_pManager->LoadFontByName(bsName, (float)dSize, lStyle, c_dDpi, c_dDpi);
SysFreeString(bsName);
LoadFontMetrics();
m_oFont.m_oProperties.m_strFamilyName = m_oFont.m_oFont.Name;
m_oFont.m_oProperties.m_lStyle = m_oFont.m_oFont.GetStyle();
m_strCurrentPickFont = m_oFont.m_oProperties.m_strFamilyName;
m_lCurrentPictFontStyle = m_oFont.m_oProperties.m_lStyle;
m_oFont.m_oProperties.m_lAvgWidth = -1;
}
void LoadFontByFile(CString& strPath, const double& dSize, const LONG& lFaceIndex)
{
BSTR bsPath = strPath.AllocSysString();
m_pManager->LoadFontFromFile(bsPath, (float)dSize, c_dDpi, c_dDpi, lFaceIndex);
SysFreeString(bsPath);
m_oFont.m_oProperties.m_strFamilyName = m_oFont.m_oFont.Name;
m_oFont.m_oProperties.m_lStyle = m_oFont.m_oFont.GetStyle();
m_strCurrentPickFont = m_oFont.m_oProperties.m_strFamilyName;
m_lCurrentPictFontStyle = m_oFont.m_oProperties.m_lStyle;
m_oFont.m_oProperties.m_lAvgWidth = -1;
LoadFontMetrics();
LoadFontParams();
}
public:
AVSINLINE void MeasureString(const CString& strText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
BSTR bsText = strText.AllocSysString();
MeasureString(bsText, x, y, dBoxX, dBoxY, dBoxWidth, dBoxHeight, measureType);
SysFreeString(bsText);
}
AVSINLINE void MeasureString(BSTR bsText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
dBoxX = 0;
dBoxY = 0;
dBoxWidth = 0;
dBoxHeight = 0;
if (NULL == m_pManager)
return;
m_pManager->LoadString(bsText, (float)x, (float)y);
float fx = 0;
float fy = 0;
float fwidth = 0;
float fheight = 0;
if (MeasureTypeGlyph == measureType)
{
m_pManager->MeasureString(&fx, &fy, &fwidth, &fheight);
}
else if (MeasureTypePosition == measureType)
{
m_pManager->MeasureString2(&fx, &fy, &fwidth, &fheight);
}
dBoxX = (double)fx;
dBoxY = (double)fy;
dBoxWidth = (double)fwidth;
dBoxHeight = (double)fheight;
//
dBoxX *= c_dPixToMM;
dBoxY *= c_dPixToMM;
dBoxWidth *= c_dPixToMM;
dBoxHeight *= c_dPixToMM;
}
AVSINLINE void MeasureStringPix(const CString& strText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
BSTR bsText = strText.AllocSysString();
MeasureString(bsText, x, y, dBoxX, dBoxY, dBoxWidth, dBoxHeight, measureType);
SysFreeString(bsText);
}
AVSINLINE void MeasureStringPix(BSTR bsText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
dBoxX = 0;
dBoxY = 0;
dBoxWidth = 0;
dBoxHeight = 0;
if (NULL == m_pManager)
return;
m_pManager->LoadString(bsText, (float)x, (float)y);
float fx = 0;
float fy = 0;
float fwidth = 0;
float fheight = 0;
if (MeasureTypeGlyph == measureType)
{
m_pManager->MeasureString(&fx, &fy, &fwidth, &fheight);
}
else if (MeasureTypePosition == measureType)
{
m_pManager->MeasureString2(&fx, &fy, &fwidth, &fheight);
}
dBoxX = (double)fx;
dBoxY = (double)fy;
dBoxWidth = (double)fwidth;
dBoxHeight = (double)fheight;
}
public:
void LoadFontMetrics()
{
unsigned short iTemp = 0;
m_pManager->GetCellAscent(&iTemp);
m_oFont.m_dAscent = iTemp;
m_pManager->GetCellDescent(&iTemp);
m_oFont.m_dDescent = iTemp;
m_pManager->GetLineSpacing(&iTemp);
m_oFont.m_dLineSpacing = iTemp;
m_pManager->GetEmHeight(&iTemp);
m_oFont.m_dEmHeight = iTemp;
m_oFont.m_dBaselineOffsetDOCX = (c_dPtToMM * m_oFont.m_dDescent * m_oFont.m_oFont.Size / m_oFont.m_dEmHeight);
double d1 = 3 * (m_oFont.m_dLineSpacing - m_oFont.m_dDescent) - m_oFont.m_dAscent;
d1 /= 2.0;
d1 *= (m_oFont.m_oFont.Size / m_oFont.m_dEmHeight);
m_oFont.m_dBaselineOffsetHTML = d1;
m_oFont.m_dLineSpacingMM = c_dPtToMM * m_oFont.m_oFont.Size * m_oFont.m_dLineSpacing / m_oFont.m_dEmHeight;
}
void LoadFontParams()
{
//
if (NULL == m_pManager)
return;
// path
CAtlMap<CString, CFontProperties>::CPair* pPair = m_mapFontPathToProperties.Lookup(m_oFont.m_oFont.Path);
if (NULL != pPair)
{
m_oFont.m_oProperties = pPair->m_value;
return;
}
if (_T("") == m_oFont.m_oFont.Name)
{
// FamilyName
BSTR bsFamilyName = NULL;
m_pManager->GetFamilyNameEx(_bstr_t("<DeletePDFPrefix/>"), &bsFamilyName);
m_oFont.m_oProperties.m_strFamilyName = (CString)bsFamilyName;
SysFreeString(bsFamilyName);
}
else
{
m_oFont.m_oProperties.m_strFamilyName = m_oFont.m_oFont.Name;
}
// StyleName
BSTR bsStyleName = NULL;
m_pManager->GetStyleName(&bsStyleName);
CString strStyle = (CString)bsStyleName;
SysFreeString(bsStyleName);
if (_T("Bold") == strStyle)
{
m_oFont.m_oProperties.m_lStyle = 0x01;
}
else if (_T("Italic") == strStyle)
{
m_oFont.m_oProperties.m_lStyle = 0x02;
}
else if (_T("Bold Italic") == strStyle)
{
m_oFont.m_oProperties.m_lStyle = 0x03;
}
else
{
m_oFont.m_oProperties.m_lStyle = 0x00;
}
AVSGraphics::IAVSFontManager2* pManager2 = NULL;
m_pManager->QueryInterface(AVSGraphics::IID_IAVSFontManager2, (void**)&pManager2);
BSTR bsPanose = NULL;
if (NULL != pManager2)
{
pManager2->GetPanose2(&bsPanose);
RELEASEINTERFACE(pManager2);
}
if (NULL != bsPanose)
{
m_oFont.m_oProperties.m_strPANOSE = (CString)bsPanose;
SysFreeString(bsPanose);
}
else
{
m_oFont.m_oProperties.m_strPANOSE = _T("");
}
// IsFixed
LONG lIsFixedWidthLong = 0;
m_pManager->IsFixedWidth(&lIsFixedWidthLong);
m_oFont.m_oProperties.m_bIsFixedWidth = (lIsFixedWidthLong != 0) ? true : false;
// Signature
VARIANT_BOOL vbSuccess = VARIANT_FALSE;
m_oFont.m_oProperties.m_arSignature.RemoveAll();
for ( unsigned int i = 0; i < 6; i++ )
{
DWORD value = 0;
for ( unsigned long bit = 0; bit < 32; bit++ )
{
m_pManager->IsUnicodeRangeAvailable( bit, i, &vbSuccess );
if( VARIANT_TRUE == vbSuccess )
{
value |= ( 1 << bit );
}
}
m_oFont.m_oProperties.m_arSignature.Add(value);
}
if (m_bIsUseFontWidth)
{
wchar_t wsDrive[MAX_PATH], wsDir[MAX_PATH], wsFilename[MAX_PATH], wsExt[MAX_PATH];
_wsplitpath( m_oFont.m_oFont.Path.GetBuffer(), wsDrive, wsDir, wsFilename, wsExt );
CString wsEncodingPath = CString(wsDrive) + CString(wsDir) + CString(wsFilename) + CString(_T(".enc"));
bool bIsCID = false;
CString strExt(wsExt);
if (-1 != strExt.Find(_T("cid")))
bIsCID = true;
XmlUtils::CXmlNode oMainNode;
oMainNode.FromXmlFile(wsEncodingPath);
if (_T("PDF-resources") == oMainNode.GetName())
{
if (bIsCID)
{
XmlUtils::CXmlNode oType0Node;
if ( oMainNode.GetNode( _T("Type0"), oType0Node ) )
{
XmlUtils::CXmlNode oNode;
if ( oType0Node.GetNode( _T("DescendantFonts"), oNode ) )
{
XmlUtils::CXmlNode oDescNode;
if ( oNode.GetNode( _T("FontDescriptor"), oDescNode ) )
{
XmlUtils::CXmlNode oCurNode;
if ( oNode.GetNode( _T("AvgWidth"), oCurNode ) )
{
CString sValue = oCurNode.GetAttribute( _T("value") );
m_oFont.m_oProperties.m_lAvgWidth = XmlUtils::GetInteger( sValue );
}
}
}
}
}
else
{
XmlUtils::CXmlNode oNode;
if ( oMainNode.GetNode( _T("FontDescriptor"), oNode ) )
{
XmlUtils::CXmlNode oCurNode;
if ( oNode.GetNode( _T("AvgWidth"), oCurNode ) )
{
CString sValue = oCurNode.GetAttribute( _T("value") );
m_oFont.m_oProperties.m_lAvgWidth = XmlUtils::GetInteger( sValue );
}
else
{
XmlUtils::CXmlNode oNodeWidths;
if (oMainNode.GetNode(_T("Widths"), oNodeWidths))
{
LONG lCount = 0;
double dWidth = 0;
XmlUtils::CXmlNodes oNodesW;
if (oNodeWidths.GetNodes(_T("Width"), oNodesW))
{
int nCountW = oNodesW.GetCount();
for (int i = 0; i < nCountW; ++i)
{
XmlUtils::CXmlNode oNodeMem;
oNodesW.GetAt(i, oNodeMem);
double dMem = XmlUtils::GetDouble(oNodeMem.GetAttribute(_T("value")));
if (0 < dMem)
{
++lCount;
dWidth += dMem;
}
}
}
if (10 < lCount)
{
m_oFont.m_oProperties.m_lAvgWidth = (LONG)(0.8 * dWidth / lCount);
}
}
}
}
}
}
}
m_mapFontPathToProperties.SetAt(m_oFont.m_oFont.Path, m_oFont.m_oProperties);
}
private:
void InitializeRanges()
{
memset(m_pRanges, 0xFF, 0xFFFF);
memset(m_pRangesNums, 0xFF, 0xFFFF);
//
int nStart = 0;
int nCount = 0;
// rangeNum 0
// case 00: sUCRName = "Basic Latin"; break; /* U+0020-U+007E */
nStart = 0x0020;
nCount = 0x007E - nStart + 1;
memset(m_pRanges + nStart, 0, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 01: sUCRName = "Latin-1 Supplement"; break; /* U+0080-U+00FF */
nStart = 0x0080;
nCount = 0x00FF - nStart + 1;
memset(m_pRanges + nStart, 1, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 02: sUCRName = "Latin Extended-A"; break; /* U+0100-U+017F */
nStart = 0x0100;
nCount = 0x017F - nStart + 1;
memset(m_pRanges + nStart, 2, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 03: sUCRName = "Latin Extended-B"; break; /* U+0180-U+024F */
nStart = 0x0180;
nCount = 0x024F - nStart + 1;
memset(m_pRanges + nStart, 3, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 04: sUCRName = "IPA Extensions"; break; /* U+0250-U+02AF */ /* U+1D00-U+1D7F */ /* U+1D80-U+1DBF */
nStart = 0x0250;
nCount = 0x02AF - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x1D00;
nCount = 0x1D7F - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x1D80;
nCount = 0x1DBF - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 05: sUCRName = "Spacing Modifier Letters"; break; /* U+02B0-U+02FF */ /* U+A700-U+A71F */
nStart = 0x02B0;
nCount = 0x02FF - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0xA700;
nCount = 0xA71F - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 06: sUCRName = "Combining Diacritical Marks"; break; /* U+0300-U+036F */ /* U+1DC0-U+1DFF */
nStart = 0x0300;
nCount = 0x036F - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x1DC0;
nCount = 0x1DFF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 07: sUCRName = "Greek and Coptic"; break; /* U+0370-U+03FF */
nStart = 0x0370;
nCount = 0x03FF - nStart + 1;
memset(m_pRanges + nStart, 7, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 08: sUCRName = "Coptic"; break; /* U+2C80-U+2CFF */
nStart = 0x2C80;
nCount = 0x2CFF - nStart + 1;
memset(m_pRanges + nStart, 8, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 09: sUCRName = "Cyrillic"; break; /* U+0400-U+04FF */ /* U+0500-U+052F */ /* U+2DE0-U+2DFF */ /* U+A640-U+A69F */
nStart = 0x0400;
nCount = 0x04FF - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x0500;
nCount = 0x052F - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x2DE0;
nCount = 0x2DFF - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0xA640;
nCount = 0xA69F - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 10: sUCRName = "Armenian"; break; /* U+0530-U+058F */
nStart = 0x0530;
nCount = 0x058F - nStart + 1;
memset(m_pRanges + nStart, 10, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 11: sUCRName = "Hebrew"; break; /* U+0590-U+05FF */
nStart = 0x0590;
nCount = 0x05FF - nStart + 1;
memset(m_pRanges + nStart, 11, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 12: sUCRName = "Vai"; break; /* U+A500-U+A63F */
nStart = 0xA500;
nCount = 0xA63F - nStart + 1;
memset(m_pRanges + nStart, 12, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 13: sUCRName = "Arabic"; break; /* U+0600-U+06FF */ /* U+0750-U+077F */
nStart = 0x0600;
nCount = 0x06FF - nStart + 1;
memset(m_pRanges + nStart, 13, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x0750;
nCount = 0x077F - nStart + 1;
memset(m_pRanges + nStart, 13, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 14: sUCRName = "NKo"; break; /* U+07C0-U+07FF */
nStart = 0x07C0;
nCount = 0x07FF - nStart + 1;
memset(m_pRanges + nStart, 14, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 15: sUCRName = "Devanagari"; break; /* U+0900-U+097F */
nStart = 0x0900;
nCount = 0x097F - nStart + 1;
memset(m_pRanges + nStart, 15, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 16: sUCRName = "Bengali"; break; /* U+0980-U+09FF */
nStart = 0x0980;
nCount = 0x09FF - nStart + 1;
memset(m_pRanges + nStart, 16, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 17: sUCRName = "Gurmukhi"; break; /* U+0A00-U+0A7F */
nStart = 0x0A00;
nCount = 0x0A7F - nStart + 1;
memset(m_pRanges + nStart, 17, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 18: sUCRName = "Gujarati"; break; /* U+0A80-U+0AFF */
nStart = 0x0A80;
nCount = 0x0AFF - nStart + 1;
memset(m_pRanges + nStart, 18, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 19: sUCRName = "Oriya"; break; /* U+0B00-U+0B7F */
nStart = 0x0B00;
nCount = 0x0B7F - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 20: sUCRName = "Tamil"; break; /* U+0B80-U+0BFF */
nStart = 0x0B80;
nCount = 0x0BFF - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 21: sUCRName = "Telugu"; break; /* U+0C00-U+0C7F */
nStart = 0x0C00;
nCount = 0x0C7F - nStart + 1;
memset(m_pRanges + nStart, 21, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 22: sUCRName = "Kannada"; break; /* U+0C80-U+0CFF */
nStart = 0x0C80;
nCount = 0x0CFF - nStart + 1;
memset(m_pRanges + nStart, 22, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 23: sUCRName = "Malayalam"; break; /* U+0D00-U+0D7F */
nStart = 0x0D00;
nCount = 0x0D7F - nStart + 1;
memset(m_pRanges + nStart, 23, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 24: sUCRName = "Thai"; break; /* U+0E00-U+0E7F */
nStart = 0x0E00;
nCount = 0x0E7F - nStart + 1;
memset(m_pRanges + nStart, 24, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 25: sUCRName = "Lao"; break; /* U+0E80-U+0EFF */
nStart = 0x0E80;
nCount = 0x0EFF - nStart + 1;
memset(m_pRanges + nStart, 25, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 26: sUCRName = "Georgian"; break; /* U+10A0-U+10FF */ /* U+2D00-U+2D2F */
nStart = 0x10A0;
nCount = 0x10FF - nStart + 1;
memset(m_pRanges + nStart, 26, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x2D00;
nCount = 0x2D2F - nStart + 1;
memset(m_pRanges + nStart, 26, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 27: sUCRName = "Balinese"; break; /* U+1B00-U+1B7F */
nStart = 0x1B00;
nCount = 0x1B7F - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 28: sUCRName = "Hangul Jamo"; break; /* U+1100-U+11FF */
nStart = 0x1100;
nCount = 0x11FF - nStart + 1;
memset(m_pRanges + nStart, 28, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 29: sUCRName = "Latin Extended Additional"; break; /* U+1E00-U+1EFF */ /* U+2C60-U+2C7F */ /* U+A720-U+A7FF */
nStart = 0x1E00;
nCount = 0x1EFF - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x2C60;
nCount = 0x2C7F - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0xA720;
nCount = 0xA7FF - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 30: sUCRName = "Greek Extended"; break; /* U+1F00-U+1FFF */
nStart = 0x1F00;
nCount = 0x1FFF - nStart + 1;
memset(m_pRanges + nStart, 30, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 31: sUCRName = "General Punctuation"; break; /* U+2000-U+206F */ /* U+2E00-U+2E7F */
nStart = 0x2000;
nCount = 0x206F - nStart + 1;
memset(m_pRanges + nStart, 31, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x2E00;
nCount = 0x2E7F - nStart + 1;
memset(m_pRanges + nStart, 31, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
// rangeNum 1
//case 00: sUCRName = "Superscripts And Subscripts"; break; /* U+2070-U+209F */
nStart = 0x2070;
nCount = 0x209F - nStart + 1;
memset(m_pRanges + nStart, 0, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 01: sUCRName = "Currency Symbols"; break; /* U+20A0-U+20CF */
nStart = 0x20A0;
nCount = 0x20CF - nStart + 1;
memset(m_pRanges + nStart, 1, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 02: sUCRName = "Combining Diacritical Marks For Symbols"; break; /* U+20D0-U+20FF */
nStart = 0x20D0;
nCount = 0x20FF - nStart + 1;
memset(m_pRanges + nStart, 2, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 03: sUCRName = "Letterlike Symbols"; break; /* U+2100-U+214F */
nStart = 0x2100;
nCount = 0x214F - nStart + 1;
memset(m_pRanges + nStart, 3, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 04: sUCRName = "Number Forms"; break; /* U+2150-U+218F */
nStart = 0x2150;
nCount = 0x218F - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 05: sUCRName = "Arrows"; break; /* U+2190-U+21FF */ /* U+27F0-U+27FF */ /* U+2900-U+297F */ /* U+2B00-U+2BFF */
nStart = 0x2190;
nCount = 0x21FF - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x27F0;
nCount = 0x27FF - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2900;
nCount = 0x297F - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2B00;
nCount = 0x2BFF - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 06: sUCRName = "Mathematical Operators"; break; /* U+2200-U+22FF */ /* U+2A00-U+2AFF */ /* U+27C0-U+27EF */ /* U+2980-U+29FF */
nStart = 0x2200;
nCount = 0x22FF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2A00;
nCount = 0x2AFF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x27C0;
nCount = 0x27EF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2980;
nCount = 0x29FF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 07: sUCRName = "Miscellaneous Technical"; break; /* U+2300-U+23FF */
nStart = 0x2300;
nCount = 0x23FF - nStart + 1;
memset(m_pRanges + nStart, 7, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 08: sUCRName = "Control Pictures"; break; /* U+2400-U+243F */
nStart = 0x2400;
nCount = 0x243F - nStart + 1;
memset(m_pRanges + nStart, 8, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 09: sUCRName = "Optical Character Recognition"; break; /* U+2440-U+245F */
nStart = 0x2440;
nCount = 0x245F - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 10: sUCRName = "Enclosed Alphanumerics"; break; /* U+2460-U+24FF */
nStart = 0x2460;
nCount = 0x24FF - nStart + 1;
memset(m_pRanges + nStart, 10, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 11: sUCRName = "Box Drawing"; break; /* U+2500-U+257F */
nStart = 0x2500;
nCount = 0x257F - nStart + 1;
memset(m_pRanges + nStart, 11, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 12: sUCRName = "Block Elements"; break; /* U+2580-U+259F */
nStart = 0x2580;
nCount = 0x259F - nStart + 1;
memset(m_pRanges + nStart, 12, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 13: sUCRName = "Geometric Shapes"; break; /* U+25A0-U+25FF */
nStart = 0x25A0;
nCount = 0x25FF - nStart + 1;
memset(m_pRanges + nStart, 13, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 14: sUCRName = "Miscellaneous Symbols"; break; /* U+2600-U+26FF */
nStart = 0x2600;
nCount = 0x26FF - nStart + 1;
memset(m_pRanges + nStart, 14, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 15: sUCRName = "Dingbats"; break; /* U+2700-U+27BF */
nStart = 0x2700;
nCount = 0x27BF - nStart + 1;
memset(m_pRanges + nStart, 15, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 16: sUCRName = "CJK Symbols and Punctuation"; break; /* U+3000-U+303F */
nStart = 0x3000;
nCount = 0x303F - nStart + 1;
memset(m_pRanges + nStart, 16, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 17: sUCRName = "Hiragana"; break; /* U+3040-U+309F */
nStart = 0x3040;
nCount = 0x309F - nStart + 1;
memset(m_pRanges + nStart, 17, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 18: sUCRName = "Katakana"; break; /* U+30A0-U+30FF */ /* U+31F0-U+31FF */
nStart = 0x30A0;
nCount = 0x30FF - nStart + 1;
memset(m_pRanges + nStart, 18, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x31F0;
nCount = 0x31FF - nStart + 1;
memset(m_pRanges + nStart, 18, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 19: sUCRName = "Bopomofo"; break; /* U+3100-U+312F */ /* U+31A0-U+31BF */
nStart = 0x3100;
nCount = 0x312F - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x31A0;
nCount = 0x31BF - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 20: sUCRName = "Hangul Compatibility Jamo"; break; /* U+3130-U+318F */
nStart = 0x3130;
nCount = 0x318F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 21: sUCRName = "Phags-pa"; break; /* U+A840-U+A87F */
nStart = 0xA840;
nCount = 0xA87F - nStart + 1;
memset(m_pRanges + nStart, 21, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 22: sUCRName = "Enclosed CJK Letters and Months"; break; /* U+3200-U+32FF */
nStart = 0x3200;
nCount = 0x32FF - nStart + 1;
memset(m_pRanges + nStart, 22, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 23: sUCRName = "CJK Compatibility"; break; /* U+3300-U+33FF */
nStart = 0x3300;
nCount = 0x33FF - nStart + 1;
memset(m_pRanges + nStart, 23, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 24: sUCRName = "Hangul Syllables"; break; /* U+AC00-U+D7AF */
nStart = 0xAC00;
nCount = 0xD7AF - nStart + 1;
memset(m_pRanges + nStart, 24, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 25: sUCRName = "Non-Plane 0"; break; /* U+D800-U+DB7F */ /* U+DB80-U+DBFF */ /* U+DC00-U+DFFF */ //
nStart = 0xD800;
nCount = 0xDB7F - nStart + 1;
memset(m_pRanges + nStart, 25, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0xDB80;
nCount = 0xDBFF - nStart + 1;
memset(m_pRanges + nStart, 25, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0xDC00;
nCount = 0xDFFF - nStart + 1;
memset(m_pRanges + nStart, 25, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 26: sUCRName = "Phoenician"; break; /*U+10900-U+1091F*/
//case 27: sUCRName = "CJK Unified Ideographs"; break; /* U+4E00-U+9FFF */ /* U+2E80-U+2EFF */ /* U+2F00-U+2FDF */ /* U+2FF0-U+2FFF */ /* U+3400-U+4DB5 */ /*U+20000-U+2A6D6*/ /* U+3190-U+319F */
nStart = 0x4E00;
nCount = 0x9FFF - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2E80;
nCount = 0x2EFF - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2F00;
nCount = 0x2FDF - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2FF0;
nCount = 0x2FFF - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x3400;
nCount = 0x4DB5 - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x3190;
nCount = 0x319F - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 28: sUCRName = "Private Use Area (plane 0)"; break; /* U+E000-U+F8FF */ //
nStart = 0xE000;
nCount = 0xF8FF - nStart + 1;
memset(m_pRanges + nStart, 28, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 29: sUCRName = "CJK Strokes"; break; /* U+31C0-U+31EF */ /* U+F900-U+FAFF */ /*U+2F800-U+2FA1F*/
nStart = 0x31C0;
nCount = 0x31EF - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0xF900;
nCount = 0xFAFF - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 30: sUCRName = "Alphabetic Presentation Forms"; break; /* U+FB00-U+FB4F */
nStart = 0xFB00;
nCount = 0xFB4F - nStart + 1;
memset(m_pRanges + nStart, 30, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 31: sUCRName = "Arabic Presentation Forms-A"; break; /* U+FB50-U+FDFF */
nStart = 0xFB50;
nCount = 0xFDFF - nStart + 1;
memset(m_pRanges + nStart, 31, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
// rangeNum 2
//case 00: sUCRName = "Combining Half Marks"; break; /* U+FE20-U+FE2F */
nStart = 0xFE20;
nCount = 0xFE2F - nStart + 1;
memset(m_pRanges + nStart, 0, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 01: sUCRName = "Vertical forms"; break; /* U+FE10-U+FE1F */ /* U+FE30-U+FE4F */
nStart = 0xFE10;
nCount = 0xFE1F - nStart + 1;
memset(m_pRanges + nStart, 1, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0xFE30;
nCount = 0xFE4F - nStart + 1;
memset(m_pRanges + nStart, 1, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 02: sUCRName = "Small Form Variants"; break; /* U+FE50-U+FE6F */
nStart = 0xFE50;
nCount = 0xFE6F - nStart + 1;
memset(m_pRanges + nStart, 2, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 03: sUCRName = "Arabic Presentation Forms-B"; break; /* U+FE70-U+FEFE */
nStart = 0xFE70;
nCount = 0xFEFE - nStart + 1;
memset(m_pRanges + nStart, 3, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 04: sUCRName = "Halfwidth and Fullwidth Forms"; break; /* U+FF00-U+FFEF */
nStart = 0xFF00;
nCount = 0xFFEF - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 05: sUCRName = "Specials"; break; /* U+FFF0-U+FFFF */
nStart = 0xFFF0;
nCount = 0xFFFF - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 06: sUCRName = "Tibetan"; break; /* U+0F00-U+0FFF */
nStart = 0x0F00;
nCount = 0x0FFF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 07: sUCRName = "Syriac"; break; /* U+0700-U+074F */
nStart = 0x0700;
nCount = 0x074F - nStart + 1;
memset(m_pRanges + nStart, 7, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 08: sUCRName = "Thaana"; break; /* U+0780-U+07BF */
nStart = 0x0780;
nCount = 0x07BF - nStart + 1;
memset(m_pRanges + nStart, 8, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 09: sUCRName = "Sinhala"; break; /* U+0D80-U+0DFF */
nStart = 0x0D80;
nCount = 0x0DFF - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 10: sUCRName = "Myanmar"; break; /* U+1000-U+109F */
nStart = 0x1000;
nCount = 0x109F - nStart + 1;
memset(m_pRanges + nStart, 10, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 11: sUCRName = "Ethiopic"; break; /* U+1200-U+137F */ /* U+1380-U+139F */ /* U+2D80-U+2DDF */
nStart = 0x1200;
nCount = 0x137F - nStart + 1;
memset(m_pRanges + nStart, 11, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x1380;
nCount = 0x139F - nStart + 1;
memset(m_pRanges + nStart, 11, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x2D80;
nCount = 0x2DDF - nStart + 1;
memset(m_pRanges + nStart, 11, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 12: sUCRName = "Cherokee"; break; /* U+13A0-U+13FF */
nStart = 0x13A0;
nCount = 0x13FF - nStart + 1;
memset(m_pRanges + nStart, 12, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 13: sUCRName = "Unified Canadian Aboriginal Syllabics"; break; /* U+1400-U+167F */
nStart = 0x1400;
nCount = 0x167F - nStart + 1;
memset(m_pRanges + nStart, 13, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 14: sUCRName = "Ogham"; break; /* U+1680-U+169F */
nStart = 0x1680;
nCount = 0x169F - nStart + 1;
memset(m_pRanges + nStart, 14, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 15: sUCRName = "Runic"; break; /* U+16A0-U+16FF */
nStart = 0x16A0;
nCount = 0x16FF - nStart + 1;
memset(m_pRanges + nStart, 15, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 16: sUCRName = "Khmer"; break; /* U+1780-U+17FF */ /* U+19E0-U+19FF */
nStart = 0x1780;
nCount = 0x17FF - nStart + 1;
memset(m_pRanges + nStart, 16, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x19E0;
nCount = 0x19FF - nStart + 1;
memset(m_pRanges + nStart, 16, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 17: sUCRName = "Mongolian"; break; /* U+1800-U+18AF */
nStart = 0x1800;
nCount = 0x18AF - nStart + 1;
memset(m_pRanges + nStart, 17, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 18: sUCRName = "Braille Patterns"; break; /* U+2800-U+28FF */
nStart = 0x2800;
nCount = 0x28FF - nStart + 1;
memset(m_pRanges + nStart, 18, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 19: sUCRName = "Yi Syllables"; break; /* U+A000-U+A48F */ /* U+A490-U+A4CF */
nStart = 0xA000;
nCount = 0xA48F - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0xA490;
nCount = 0xA4CF - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 20: sUCRName = "Tagalog"; break; /* U+1700-U+171F */ /* U+1720-U+173F */ /* U+1740-U+175F */ /* U+1760-U+177F */
nStart = 0x1700;
nCount = 0x171F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x1720;
nCount = 0x173F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x1740;
nCount = 0x175F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x1760;
nCount = 0x177F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 21: sUCRName = "Old Italic"; break; /*U+10300-U+1032F*/
//case 22: sUCRName = "Gothic"; break; /*U+10330-U+1034F*/
//case 23: sUCRName = "Deseret"; break; /*U+10400-U+1044F*/
//case 24: sUCRName = "Byzantine Musical Symbols"; break; /*U+1D000-U+1D0FF*/ /*U+1D100-U+1D1FF*/ /*U+1D200-U+1D24F*/
//case 25: sUCRName = "Mathematical Alphanumeric Symbols"; break; /*U+1D400-U+1D7FF*/
//case 26: sUCRName = "Private Use (plane 15)"; break; /*U+F0000-U+FFFFD*/ /*U+100000-U+10FFFD*/ //
//case 27: sUCRName = "Variation Selectors"; break; /* U+FE00-U+FE0F */ /*U+E0100-U+E01EF*/
nStart = 0xFE00;
nCount = 0xFE0F - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 28: sUCRName = "Tags"; break; /*U+E0000-U+E007F*/
//case 29: sUCRName = "Limbu"; break; /* U+1900-U+194F */
nStart = 0x1900;
nCount = 0x194F - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 30: sUCRName = "Tai Le"; break; /* U+1950-U+197F */
nStart = 0x1950;
nCount = 0x197F - nStart + 1;
memset(m_pRanges + nStart, 30, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 31: sUCRName = "New Tai Lue"; break; /* U+1980-U+19DF */
nStart = 0x1980;
nCount = 0x19DF - nStart + 1;
memset(m_pRanges + nStart, 31, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
// rangeNum 3
//case 00: sUCRName = "Buginese"; break; /* U+1A00-U+1A1F */
nStart = 0x1A00;
nCount = 0x1A1F - nStart + 1;
memset(m_pRanges + nStart, 0, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 01: sUCRName = "Glagolitic"; break; /* U+2C00-U+2C5F */
nStart = 0x2C00;
nCount = 0x2C5F - nStart + 1;
memset(m_pRanges + nStart, 1, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 02: sUCRName = "Tifinagh"; break; /* U+2D30-U+2D7F */
nStart = 0x2D30;
nCount = 0x2D7F - nStart + 1;
memset(m_pRanges + nStart, 2, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 03: sUCRName = "Yijing Hexagram Symbols"; break; /* U+4DC0-U+4DFF */
nStart = 0x4DC0;
nCount = 0x4DFF - nStart + 1;
memset(m_pRanges + nStart, 3, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 04: sUCRName = "Syloti Nagri"; break; /* U+A800-U+A82F */
nStart = 0xA800;
nCount = 0xA82F - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 05: sUCRName = "Linear B Syllabary"; break; /*U+10000-U+1007F*/ /*U+10080-U+100FF*/ /*U+10100-U+1013F*/
//case 06: sUCRName = "Ancient Greek Numbers"; break; /*U+10140-U+1018F*/
//case 07: sUCRName = "Ugaritic"; break; /*U+10380-U+1039F*/
//case 08: sUCRName = "Old Persian"; break; /*U+103A0-U+103DF*/
//case 09: sUCRName = "Shavian"; break; /*U+10450-U+1047F*/
//case 10: sUCRName = "Osmanya"; break; /*U+10480-U+104AF*/
//case 11: sUCRName = "Cypriot Syllabary"; break; /*U+10800-U+1083F*/
//case 12: sUCRName = "Kharoshthi"; break; /*U+10A00-U+10A5F*/
//case 13: sUCRName = "Tai Xuan Jing Symbols"; break; /*U+1D300-U+1D35F*/
//case 14: sUCRName = "Cuneiform"; break; /*U+12000-U+123FF*/ /*U+12400-U+1247F*/
//case 15: sUCRName = "Counting Rod Numerals"; break; /*U+1D360-U+1D37F*/
//case 16: sUCRName = "Sundanese"; break; /* U+1B80-U+1BBF */
nStart = 0x1B80;
nCount = 0x1BBF - nStart + 1;
memset(m_pRanges + nStart, 16, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 17: sUCRName = "Lepcha"; break; /* U+1C00-U+1C4F */
nStart = 0x1C00;
nCount = 0x1C4F - nStart + 1;
memset(m_pRanges + nStart, 17, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 18: sUCRName = "Ol Chiki"; break; /* U+1C50-U+1C7F */
nStart = 0x1C50;
nCount = 0x1C7F - nStart + 1;
memset(m_pRanges + nStart, 18, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 19: sUCRName = "Saurashtra"; break; /* U+A880-U+A8DF */
nStart = 0xA880;
nCount = 0xA8DF - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 20: sUCRName = "Kayah Li"; break; /* U+A900-U+A92F */
nStart = 0xA900;
nCount = 0xA92F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 21: sUCRName = "Rejang"; break; /* U+A930-U+A95F */
nStart = 0xA930;
nCount = 0xA95F - nStart + 1;
memset(m_pRanges + nStart, 21, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 22: sUCRName = "Cham"; break; /* U+AA00-U+AA5F */
nStart = 0xAA00;
nCount = 0xAA5F - nStart + 1;
memset(m_pRanges + nStart, 22, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 23: sUCRName = "Ancient Symbols"; break; /*U+10190-U+101CF*/
//case 24: sUCRName = "Phaistos Disc"; break; /*U+101D0-U+101FF*/
//case 25: sUCRName = "Carian"; break; /*U+102A0-U+102DF*/ /*U+10280-U+1029F*/ /*U+10920-U+1093F*/
//case 26: sUCRName = "Domino Tiles"; break; /*U+1F030-U+1F09F*/ /*U+1F000-U+1F02F*/
//case 27: sUCRName = "Reserved for process-internal usage"; break;
//case 28: sUCRName = "Reserved for process-internal usage"; break;
//case 29: sUCRName = "Reserved for process-internal usage"; break;
//case 30: sUCRName = "Reserved for process-internal usage"; break;
//case 31: sUCRName = "Reserved for process-internal usage"; break;
}
AVSINLINE void InitializeUnicodeMap()
{
memset(m_mapUnicode, 0, 0xFFFF);
m_mapUnicode[0x0009] = 1;
m_mapUnicode[0x000A] = 1;
m_mapUnicode[0x000D] = 1;
memset(m_mapUnicode + 0x0020, 1, 0xD7FF - 0x0020 + 1);
memset(m_mapUnicode + 0xE000, 1, 0xFFFD - 0xE000 + 1);
}
AVSINLINE bool GetRange(const WCHAR& symbol, BYTE& lRangeNum, BYTE& lRange)
{
lRangeNum = m_pRangesNums[symbol];
lRange = m_pRanges[symbol];
return (0xFF != lRangeNum);
}
AVSINLINE void CheckRanges(DWORD& lRange1, DWORD& lRange2, DWORD& lRange3, DWORD& lRange4, CString strText)
{
int lCount = strText.GetLength();
WCHAR* pData = strText.GetBuffer();
BYTE lRangeNum = 0xFF;
BYTE lRange = 0xFF;
for (int i = 0; i < lCount; ++i, ++pData)
{
if (GetRange(*pData, lRangeNum, lRange))
{
if (0 == lRangeNum)
lRange1 |= 1 << lRange;
else if (1 == lRangeNum)
lRange2 |= 1 << lRange;
else if (2 == lRangeNum)
lRange3 |= 1 << lRange;
else
lRange4 |= 1 << lRange;
}
}
}
AVSINLINE void CheckRanges(DWORD& lRange1, DWORD& lRange2, DWORD& lRange3, DWORD& lRange4, BYTE& lRangeNum, BYTE& lRange)
{
if (0 == lRangeNum)
lRange1 |= 1 << lRange;
else if (1 == lRangeNum)
lRange2 |= 1 << lRange;
else if (2 == lRangeNum)
lRange3 |= 1 << lRange;
else
lRange4 |= 1 << lRange;
}
public:
AVSINLINE bool GenerateFontName(NSCommon::CTextItem& oTextItem, bool bIsFontChanged)
{
if (_T("") == m_oFont.m_oFont.Path)
return false;
BYTE lRangeNum = 0xFF;
BYTE lRange = 0xFF;
GetRange(oTextItem[0], lRangeNum, lRange);
if (!bIsFontChanged && (0 != m_arListPicUps.GetCount()))
{
CFontPickUp& oPick = m_arListPicUps.GetHead();
if ((lRangeNum == oPick.m_lRangeNum) && (lRange == oPick.m_lRange))
{
// ,
//m_strCurrentPickFont = oPick.m_strPickFont;
//m_lCurrentPictFontStyle = oPick.m_lPickStyle;
return false;
}
}
POSITION posStart = m_arListPicUps.GetHeadPosition();
POSITION pos = posStart;
while (NULL != pos)
{
POSITION posOld = pos;
CFontPickUp& oPick = m_arListPicUps.GetNext(pos);
if ((oPick.m_oFont.m_oFont.IsEqual3(&m_oFont.m_oFont)) && (lRangeNum == oPick.m_lRangeNum) && (lRange == oPick.m_lRange))
{
// !
//
m_arListPicUps.MoveToHead(posOld);
m_strCurrentPickFont = oPick.m_strPickFont;
m_lCurrentPictFontStyle = oPick.m_lPickStyle;
return false;
}
}
// ...
m_arListPicUps.AddHead();
CFontPickUp& oPick = m_arListPicUps.GetHead();
oPick.m_lRangeNum = lRangeNum;
oPick.m_lRange = lRange;
oPick.m_oFont = m_oFont;
oPick.m_strPickFont = m_oFont.m_oProperties.m_strFamilyName;
oPick.m_lPickStyle = m_oFont.m_oProperties.m_lStyle;
AVSGraphics::IAVSFontManager2* pManager2 = NULL;
m_pManager->QueryInterface(AVSGraphics::IID_IAVSFontManager2, (void**)&pManager2);
BSTR bsFontName = m_oFont.m_oProperties.m_strFamilyName.AllocSysString();
BSTR bsNewFontName = NULL;
LONG lCountSigs = (LONG)m_oFont.m_oProperties.m_arSignature.GetCount();
DWORD dwR1 = 0;
if (0 < lCountSigs)
dwR1 = m_oFont.m_oProperties.m_arSignature[0];
DWORD dwR2 = 0;
if (1 < lCountSigs)
dwR2 = m_oFont.m_oProperties.m_arSignature[1];
DWORD dwR3 = 0;
if (2 < lCountSigs)
dwR3 = m_oFont.m_oProperties.m_arSignature[2];
DWORD dwR4 = 0;
if (3 < lCountSigs)
dwR4 = m_oFont.m_oProperties.m_arSignature[3];
DWORD dwCodePage1 = 0;
DWORD dwCodePage2 = 0;
if ((lRangeNum == 1) && (lRange == 28))
{
dwCodePage1 = 0x80000000;
//if (oTextItem[0] > 0xF000)
// oTextItem[0] = (oTextItem[0] - 0xF000);
}
else if (((lRangeNum == 2) && (lRange == 3)) || ((lRangeNum == 1) && (lRange == 31)) || ((lRangeNum == 0) && (lRange == 13)))
{
// !!!
dwR1 = 1 << 13;
dwR2 = 1 << 31;
dwR3 = 1 << 3;
}
else
{
CheckRanges(dwR1, dwR2, dwR3, dwR4, lRangeNum, lRange);
}
BSTR bsPanose = m_oFont.m_oProperties.m_strPANOSE.AllocSysString();
LONG lFontStyle = m_oFont.m_oFont.GetStyle();
pManager2->GetWinFontByParams2(&bsNewFontName, bsFontName, -1, NULL, &lFontStyle, m_oFont.m_oProperties.m_bIsFixedWidth ? 1 : 0, bsPanose,
dwR1, dwR2, dwR3, dwR4, dwCodePage1, dwCodePage2, m_oFont.m_oProperties.m_lAvgWidth);
oPick.m_strPickFont = (CString)bsNewFontName;
oPick.m_lPickStyle = lFontStyle;
m_strCurrentPickFont = oPick.m_strPickFont;
m_lCurrentPictFontStyle = oPick.m_lPickStyle;
SysFreeString(bsFontName);
SysFreeString(bsPanose);
SysFreeString(bsNewFontName);
RELEASEINTERFACE(pManager2);
return true;
}
AVSINLINE void SetStringGid(const LONG& lGid)
{
if (NULL != m_pManager)
m_pManager->SetStringGID(lGid);
}
AVSINLINE LONG GetStringGid()
{
LONG lGid = 0;
if (NULL != m_pManager)
m_pManager->GetStringGID(&lGid);
return lGid;
}
AVSINLINE wchar_t* GetUnicodeString(BSTR bsText)
{
wchar_t* start = (wchar_t*)bsText;
wchar_t* s = start;
for (; *s != 0; ++s);
LONG lLen = (LONG)(s - start);
wchar_t* pData = new wchar_t[lLen + 1];
for (LONG i = 0; i < lLen; ++i, ++start)
{
if (m_mapUnicode[*start])
pData[i] = *start;
else
pData[i] = (wchar_t)(' ');
}
return pData;
}
CString GetFontPath(NSStructures::CFont* pFont)
{
CString strXml = _T("<FontProperties><Name value=\"") + pFont->Name + _T("\"/>");
CString strStyle = _T("");
strStyle.Format(_T("<Style bold=\"%d\" italic=\"%d\"/>"), pFont->Bold ? 1 : 0, pFont->Italic ? 1 : 0);
strXml += strStyle;
strXml += _T("</FontProperties>");
BSTR bsResult = NULL;
LONG lFontIndex = NULL;
BSTR bsInput = strXml.AllocSysString();
m_pManager->GetWinFontByParams(bsInput, &bsResult, &lFontIndex);
CString strPath = (CString)bsResult;
SysFreeString(bsInput);
SysFreeString(bsResult);
return strPath;
}
};
}
\ No newline at end of file
#pragma once
#include "..\stdafx.h"
#include "../../Common/DocxFormat/Source/XML/XmlUtils.h"
#include "AVSUtils.h"
#include "..\..\..\AVSImageStudio3\AVSGraphics\Interfaces\AVSRenderer.h"
#include "ap_aggplusenums.h"
#include <gdiplus.h>
// pen -----------------------------------------------------------
const long c_ag_LineCapFlat = 0;
const long c_ag_LineCapSquare = 1;
const long c_ag_LineCapTriangle = 3;
const long c_ag_LineCapNoAnchor = 16;
const long c_ag_LineCapSquareAnchor = 17;
const long c_ag_LineCapRoundAnchor = 18;
const long c_ag_LineCapDiamondAnchor = 19;
const long c_ag_LineCapArrowAnchor = 20;
const long c_ag_LineCapAnchorMask = 240;
const long c_ag_LineCapCustom = 255;
const long c_ag_DashCapFlat = 0;
const long c_ag_DashCapRound = 2;
const long c_ag_DashCapTriangle = 3;
const long c_ag_LineJoinMiter = 0;
const long c_ag_LineJoinBevel = 1;
const long c_ag_LineJoinRound = 2;
const long c_ag_LineJoinMiterClipped = 3;
const long c_ag_PenAlignmentCenter = 0;
const long c_ag_PenAlignmentInset = 1;
const long c_ag_PenAlignmentOutset = 2;
const long c_ag_PenAlignmentLeft = 3;
const long c_ag_PenAlignmentRight = 4;
// --------------------------------------------------------------
// brush --------------------------------------------------------
// old constants for brush type
const long c_BrushTypeSolid_ = 0;
const long c_BrushTypeHorizontal_ = 1;
const long c_BrushTypeVertical_ = 2;
const long c_BrushTypeDiagonal1_ = 3;
const long c_BrushTypeDiagonal2_ = 4;
const long c_BrushTypeCenter_ = 5;
const long c_BrushTypePathGradient1_ = 6;
const long c_BrushTypePathGradient2_ = 7;
const long c_BrushTypeTexture_ = 8;
const long c_BrushTypeHatch1_ = 9;
const long c_BrushTypeHatch53_ = 61;
const long c_BrushTypeGradient1_ = 62;
const long c_BrushTypeGradient6_ = 70;
const long c_BrushTypeSolid = 1000;
const long c_BrushTypeHorizontal = 2001;
const long c_BrushTypeVertical = 2002;
const long c_BrushTypeDiagonal1 = 2003;
const long c_BrushTypeDiagonal2 = 2004;
const long c_BrushTypeCenter = 2005;
const long c_BrushTypePathGradient1 = 2006;
const long c_BrushTypePathGradient2 = 2007;
const long c_BrushTypeCylinderHor = 2008;
const long c_BrushTypeCylinderVer = 2009;
const long c_BrushTypeTexture = 3008;
const long c_BrushTypeHatch1 = 4009;
const long c_BrushTypeHatch53 = 4061;
const long c_BrushTextureModeStretch = 0;
const long c_BrushTextureModeTile = 1;
const long c_BrushTextureModeTileCenter = 2;
// --------------------------------------------------------------
//using namespace Gdiplus;
namespace NSStructures
{
class CPen
{
public:
long Color;
long Alpha;
double Size;
byte DashStyle;
byte LineStartCap;
byte LineEndCap;
byte LineJoin;
double* DashPattern;
long Count;
double DashOffset;
LONG Align;
double MiterLimit;
public:
CString ToXmlString(CString strRootNodeName = _T("pen"), BOOL bAttributed = FALSE)
{
XmlUtils::CXmlWriter oXmlWriter;
if (!bAttributed)
{
oXmlWriter.WriteNodeBegin(strRootNodeName);
oXmlWriter.WriteNode(_T("color"), Color);
oXmlWriter.WriteNode(_T("alpha"), Alpha);
oXmlWriter.WriteNode(_T("size"), Size);
oXmlWriter.WriteNode(_T("style"), DashStyle);
oXmlWriter.WriteNode(_T("line-start-cap"), LineStartCap);
oXmlWriter.WriteNode(_T("line-end-cap"), LineEndCap);
oXmlWriter.WriteNode(_T("line-join"), LineJoin);
oXmlWriter.WriteNode(_T("dash-pattern-count"), Count);
oXmlWriter.WriteNodeBegin(_T("dash-pattern"));
if (DashPattern != NULL)
{
for (int i = 0; i < Count; ++i)
{
oXmlWriter.WriteNode(_T("dash"), DashPattern[i]);
}
}
oXmlWriter.WriteNodeEnd(_T("dash-pattern"));
oXmlWriter.WriteNode(_T("dash-offset"), DashOffset);
oXmlWriter.WriteNode(_T("alignment"), Align);
oXmlWriter.WriteNodeEnd(strRootNodeName);
}
else
{
oXmlWriter.WriteNodeBegin(strRootNodeName, TRUE);
ToXmlAttributes(oXmlWriter);
oXmlWriter.WriteNodeEnd(strRootNodeName, TRUE);
}
return oXmlWriter.GetXmlString();
}
void FromXmlString(CString& strXml)
{
XmlUtils::CXmlReader oXmlReader;
oXmlReader.SetXmlString(strXml);
oXmlReader.ReadRootNode();
FromXmlAttributes(oXmlReader);
}
void ToXmlAttributes(XmlUtils::CXmlWriter& oXmlWriter)
{
oXmlWriter.WriteAttribute(_T("color"), Color);
oXmlWriter.WriteAttribute(_T("alpha"), Alpha);
oXmlWriter.WriteAttribute(_T("size"), Size);
oXmlWriter.WriteAttribute(_T("style"), DashStyle);
oXmlWriter.WriteAttribute(_T("line-start-cap"), LineStartCap);
oXmlWriter.WriteAttribute(_T("line-end-cap"), LineEndCap);
oXmlWriter.WriteAttribute(_T("line-join"), LineJoin);
oXmlWriter.WriteAttribute(_T("dash-offset"), DashOffset);
oXmlWriter.WriteAttribute(_T("alignment"), Align);
}
void FromXmlAttributes(XmlUtils::CXmlReader& oXmlReader)
{
Color = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("color"), _T("0")));
Alpha = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("alpha"), _T("0")));
Size = XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("size"), _T("0")));
DashStyle = (byte)XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("style"), _T("0")));
LineStartCap = (byte)XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("line-start-cap"), _T("0")));
LineEndCap = (byte)XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("line-end-cap"), _T("0")));
LineJoin = (byte)XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("line-join"), _T("0")));
RELEASEARRAYOBJECTS(DashPattern);
Count = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("dash-pattern-count"), _T("0")));
if (Count != 0)
{
XmlUtils::CXmlNode oPatternNode;
oXmlReader.ReadNodeList(_T("dash-pattern"));
if (oPatternNode.FromXmlString(oXmlReader.ReadNodeXml(0)))
{
XmlUtils::CXmlNodes oDashNodes;
if (oPatternNode.GetNodes(_T("dash"), oDashNodes))
{
Count = oDashNodes.GetCount();
if (Count != 0)
{
DashPattern = new double[Count];
XmlUtils::CXmlNode oDashNode;
for (int i = 0; i < Count; ++i)
{
oDashNodes.GetAt(i, oDashNode);
DashPattern[i] = XmlUtils::GetDouble(oDashNode.GetText());
}
}
}
}
}
DashOffset = XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("dash-offset"), _T("0")));
Align = XmlUtils::GetInteger(oXmlReader.ReadNodeAttribute(_T("alignment"), _T("0")));
}
void FromXmlNode(XmlUtils::CXmlNode& oXmlNode)
{
Color = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("color"), _T("0")));
Alpha = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("alpha"), _T("0")));
Size = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("size"), _T("0")));
DashStyle = (byte)XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("style"), _T("0")));
LineStartCap = (byte)XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("line-start-cap"), _T("0")));
LineEndCap = (byte)XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("line-end-cap"), _T("0")));
LineJoin = (byte)XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("line-join"), _T("0")));
RELEASEARRAYOBJECTS(DashPattern);
Count = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("dash-pattern-count"), _T("0")));
if (Count != 0)
{
XmlUtils::CXmlNode oPatternNode;
if (oXmlNode.GetNode(_T("dash-pattern"), oPatternNode))
{
XmlUtils::CXmlNodes oDashNodes;
if (oPatternNode.GetNodes(_T("dash"), oDashNodes))
{
Count = oDashNodes.GetCount();
if (Count != 0)
{
DashPattern = new double[Count];
XmlUtils::CXmlNode oDashNode;
for (int i = 0; i < Count; ++i)
{
oDashNodes.GetAt(i, oDashNode);
DashPattern[i] = XmlUtils::GetDouble(oDashNode.GetText());
}
}
}
}
}
DashOffset = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("dash-offset"), _T("0")));
Align = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("alignment"), _T("0")));
}
void FromXmlNode2(XmlUtils::CXmlNode& oXmlNode)
{
Color = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("pen-color"), _T("0")));
Alpha = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("pen-alpha"), _T("0")));
Size = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("pen-size"), _T("0")));
DashStyle = (byte)XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("pen-style"), _T("0")));
LineStartCap = (byte)XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("pen-line-start-cap"), _T("0")));
LineEndCap = (byte)XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("pen-line-end-cap"), _T("0")));
LineJoin = (byte)XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("pen-line-join"), _T("0")));
RELEASEARRAYOBJECTS(DashPattern);
Count = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("pen-dash-pattern-count"), _T("0")));
if (Count != 0)
{
XmlUtils::CXmlNode oPatternNode;
if (oXmlNode.GetNode(_T("dash-pattern"), oPatternNode))
{
XmlUtils::CXmlNodes oDashNodes;
if (oPatternNode.GetNodes(_T("dash"), oDashNodes))
{
Count = oDashNodes.GetCount();
if (Count != 0)
{
DashPattern = new double[Count];
XmlUtils::CXmlNode oDashNode;
for (int i = 0; i < Count; ++i)
{
oDashNodes.GetAt(i, oDashNode);
DashPattern[i] = XmlUtils::GetDouble(oDashNode.GetText());
}
}
}
}
}
DashOffset = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("pen-dash-offset"), _T("0")));
Align = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("pen-alignment"), _T("0")));
}
void GetDashPattern(double* arrDashPattern, long& nCount) const
{
if (nCount == Count)
{
for (int i = 0; i < Count; ++i)
{
arrDashPattern[i] = DashPattern[i];
}
}
}
void SetDashPattern(double* arrDashPattern, long nCount)
{
if ((arrDashPattern == NULL) || (nCount == 0))
{
Count = 0;
RELEASEARRAYOBJECTS(DashPattern);
}
else
{
if (Count != nCount)
{
Count = nCount;
RELEASEARRAYOBJECTS(DashPattern);
DashPattern = new double[Count];
}
for (int i = 0; i < Count; ++i)
{
DashPattern[i] = arrDashPattern[i];
}
}
}
void ScaleAlpha( double dScale )
{
long dNewAlpha = long(Alpha * dScale + 0.5);
if( dNewAlpha > 255 ) dNewAlpha = 255;
else if( dNewAlpha < 0 ) dNewAlpha = 0;
Alpha = dNewAlpha;
}
BOOL IsEqual(CPen* pPen)
{
if (NULL == pPen)
return FALSE;
return ((Color == pPen->Color) && (Alpha == pPen->Alpha) && (Size == pPen->Size) &&
(DashStyle == pPen->DashStyle) && (LineStartCap == pPen->LineStartCap) &&
(LineEndCap == pPen->LineEndCap) && (LineJoin == pPen->LineJoin));
}
void SetToRenderer(IAVSRenderer *pRenderer)
{
pRenderer->put_PenColor(Color);
pRenderer->put_PenAlpha(Alpha);
pRenderer->put_PenSize(Size);
pRenderer->put_PenDashStyle(DashStyle);
pRenderer->put_PenLineStartCap(LineStartCap);
pRenderer->put_PenLineEndCap(LineEndCap);
pRenderer->put_PenLineJoin(LineJoin);
pRenderer->put_PenAlign(Align);
if (DashStyle != Aggplus::DashStyleSolid)
{
SAFEARRAYBOUND rgsab;
rgsab.lLbound = 0;
rgsab.cElements = Count;
SAFEARRAY* pArray = SafeArrayCreate(VT_R8, 1, &rgsab);
memcpy(pArray->pvData, DashPattern, Count * sizeof(double));
pRenderer->PenDashPattern(pArray);
RELEASEARRAY(pArray);
pRenderer->put_PenDashOffset(DashOffset);
}
}
void SetDefaultParams()
{
Color = 0;
Alpha = 255;
Size = 1;
DashStyle = 0;
LineStartCap = 0;
LineEndCap = 0;
LineJoin = 0;
DashPattern = NULL;
Count = 0;
DashOffset = 0;
Align = Gdiplus::PenAlignmentCenter;
MiterLimit = 0.5;
}
public:
CPen()
{
SetDefaultParams();
}
CPen( const CPen& other )
{
*this = other;
}
CPen& operator=(const CPen& other)
{
Color = other.Color;
Alpha = other.Alpha;
Size = other.Size;
DashStyle = other.DashStyle;
LineStartCap = other.LineStartCap;
LineEndCap = other.LineEndCap;
LineJoin = other.LineJoin;
RELEASEARRAYOBJECTS(DashPattern);
Count = other.Count;
if (Count != 0)
{
DashPattern = new double[Count];
for (int i = 0; i < Count; ++i)
{
DashPattern[i] = other.DashPattern[i];
}
}
DashOffset = other.DashOffset;
Align = other.Align;
MiterLimit = other.MiterLimit;
return *this;
}
virtual ~CPen()
{
RELEASEARRAYOBJECTS(DashPattern);
}
};
class CBrush
{
public:
long Type;
long Color1;
long Color2;
long Alpha1;
long Alpha2;
CString TexturePath;
long TextureAlpha;
long TextureMode;
BOOL Rectable;
Gdiplus::RectF Rect;
double LinearAngle;
public:
CString ToXmlString(CString strRootNodeName = _T("brush"), BOOL bAttributed = TRUE)
{
XmlUtils::CXmlWriter oXmlWriter;
if (!bAttributed)
{
oXmlWriter.WriteNodeBegin(strRootNodeName);
oXmlWriter.WriteNode(_T("type"), Type);
oXmlWriter.WriteNode(_T("color1"), Color1);
oXmlWriter.WriteNode(_T("color2"), Color2);
oXmlWriter.WriteNode(_T("alpha1"), Alpha1);
oXmlWriter.WriteNode(_T("alpha2"), Alpha2);
oXmlWriter.WriteNode(_T("texturepath"), TexturePath);
oXmlWriter.WriteNode(_T("texturealpha"), TextureAlpha);
oXmlWriter.WriteNode(_T("texturemode"), TextureMode);
oXmlWriter.WriteNode(_T("rectable"), Rectable);
oXmlWriter.WriteNode(_T("linearangle"), LinearAngle);
oXmlWriter.WriteNodeBegin(_T("rectangle"), TRUE);
oXmlWriter.WriteAttribute(_T("left"), Rect.X);
oXmlWriter.WriteAttribute(_T("top"), Rect.Y);
oXmlWriter.WriteAttribute(_T("width"), Rect.Width);
oXmlWriter.WriteAttribute(_T("height"), Rect.Height);
oXmlWriter.WriteNodeEnd(_T("rectangle"), TRUE);
oXmlWriter.WriteNodeEnd(strRootNodeName);
}
else
{
oXmlWriter.WriteNodeBegin(strRootNodeName, TRUE);
ToXmlAttributes(oXmlWriter);
oXmlWriter.WriteNodeEnd(strRootNodeName, TRUE);
}
return oXmlWriter.GetXmlString();
}
void FromXmlString(CString& strXml)
{
XmlUtils::CXmlReader oXmlReader;
oXmlReader.SetXmlString(strXml);
oXmlReader.ReadRootNode();
FromXmlAttributes(oXmlReader);
}
void ToXmlAttributes(XmlUtils::CXmlWriter& oXmlWriter)
{
oXmlWriter.WriteAttribute(_T("type"), Type);
oXmlWriter.WriteAttribute(_T("color1"), Color1);
oXmlWriter.WriteAttribute(_T("color2"), Color2);
oXmlWriter.WriteAttribute(_T("alpha1"), Alpha1);
oXmlWriter.WriteAttribute(_T("alpha2"), Alpha2);
oXmlWriter.WriteAttribute(_T("texturepath"), TexturePath);
oXmlWriter.WriteAttribute(_T("texturealpha"), TextureAlpha);
oXmlWriter.WriteAttribute(_T("texturemode"), TextureMode);
oXmlWriter.WriteAttribute(_T("rectable"), Rectable);
oXmlWriter.WriteAttribute(_T("linearangle"), LinearAngle);
oXmlWriter.WriteAttribute(_T("rect-left"), Rect.X);
oXmlWriter.WriteAttribute(_T("rect-top"), Rect.Y);
oXmlWriter.WriteAttribute(_T("rect-width"), Rect.Width);
oXmlWriter.WriteAttribute(_T("rect-height"), Rect.Height);
}
void FromXmlAttributes(XmlUtils::CXmlReader& oXmlReader)
{
Type = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("type"), _T("0")));
Type = ConstantCompatible(Type);
Color1 = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("color1"), _T("0")));
Color2 = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("color2"), _T("0")));
Alpha1 = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("alpha1"), _T("0")));
Alpha2 = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("alpha2"), _T("0")));
TexturePath = oXmlReader.ReadNodeAttributeOrValue(_T("texturepath"), _T(""));
TextureAlpha = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("texturealpha"), _T("0")));
TextureMode = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("texturemode"), _T("0")));
Rectable = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("rectable"), _T("0")));
LinearAngle = XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("linearangle"), _T("0")));
Rect.X = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("rect-left")));
Rect.Y = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("rect-top")));
Rect.Width = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("rect-width")));
Rect.Height = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("rect-height")));
if (oXmlReader.ReadNode(_T("rectangle")))
{
Rect.X = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlReader.ReadNodeAttribute(_T("left")));
Rect.Y = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlReader.ReadNodeAttribute(_T("top")));
Rect.Width = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlReader.ReadNodeAttribute(_T("width")));
Rect.Height = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlReader.ReadNodeAttribute(_T("height")));
}
}
void FromXmlNode(XmlUtils::CXmlNode& oXmlNode)
{
Type = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("type"), _T("0")));
Type = ConstantCompatible(Type);
Color1 = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("color1"), _T("0")));
Color2 = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("color2"), _T("0")));
Alpha1 = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("alpha1"), _T("0")));
Alpha2 = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("alpha2"), _T("0")));
TexturePath = oXmlNode.GetAttributeOrValue(_T("texturepath"), _T(""));
TextureAlpha = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("texturealpha"), _T("0")));
TextureMode = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("texturemode"), _T("0")));
Rectable = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("rectable"), _T("0")));
LinearAngle = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("linearangle"), _T("0")));
Rect.X = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("rect-left")));
Rect.Y = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("rect-top")));
Rect.Width = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("rect-width")));
Rect.Height = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("rect-height")));
XmlUtils::CXmlNode oNodeRect;
if (oXmlNode.GetNode(_T("rectangle"), oNodeRect))
{
Rect.X = (Gdiplus::REAL)XmlUtils::GetDouble(oNodeRect.GetAttributeOrValue(_T("left")));
Rect.Y = (Gdiplus::REAL)XmlUtils::GetDouble(oNodeRect.GetAttributeOrValue(_T("top")));
Rect.Width = (Gdiplus::REAL)XmlUtils::GetDouble(oNodeRect.GetAttributeOrValue(_T("width")));
Rect.Height = (Gdiplus::REAL)XmlUtils::GetDouble(oNodeRect.GetAttributeOrValue(_T("height")));
}
}
void FromXmlNode2(XmlUtils::CXmlNode& oXmlNode)
{
Type = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("brush-type"), _T("0")));
Type = ConstantCompatible(Type);
Color1 = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("brush-color1"), _T("0")));
Color2 = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("brush-color2"), _T("0")));
Alpha1 = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("brush-alpha1"), _T("0")));
Alpha2 = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("brush-alpha2"), _T("0")));
TexturePath = oXmlNode.GetAttributeOrValue(_T("brush-texturepath"), _T(""));
TextureAlpha = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("brush-texturealpha"), _T("0")));
TextureMode = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("brush-texturemode"), _T("0")));
Rectable = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("brush-rectable"), _T("0")));
LinearAngle = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("brush-linearangle"), _T("0")));
Rect.X = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("brush-rect-left")));
Rect.Y = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("brush-rect-top")));
Rect.Width = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("brush-rect-width")));
Rect.Height = (Gdiplus::REAL)XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("brush-rect-height")));
XmlUtils::CXmlNode oNodeRect;
if (oXmlNode.GetNode(_T("brush-rectangle"), oNodeRect))
{
Rect.X = (Gdiplus::REAL)XmlUtils::GetDouble(oNodeRect.GetAttributeOrValue(_T("left")));
Rect.Y = (Gdiplus::REAL)XmlUtils::GetDouble(oNodeRect.GetAttributeOrValue(_T("top")));
Rect.Width = (Gdiplus::REAL)XmlUtils::GetDouble(oNodeRect.GetAttributeOrValue(_T("width")));
Rect.Height = (Gdiplus::REAL)XmlUtils::GetDouble(oNodeRect.GetAttributeOrValue(_T("height")));
}
}
inline LONG ConstantCompatible(LONG nConstant)
{
if( c_BrushTypeDiagonal1_ == nConstant )
nConstant = c_BrushTypeDiagonal2_;
else if( c_BrushTypeDiagonal2_ == nConstant )
nConstant = c_BrushTypeDiagonal1_;
if (1000 <= nConstant)
return nConstant;
if (c_BrushTypeSolid_ == nConstant)
return nConstant + 1000;
if (c_BrushTypeHorizontal_ <= nConstant && c_BrushTypePathGradient2_ >= nConstant)
return nConstant + 2000;
if (c_BrushTypeTexture_ == nConstant)
return nConstant + 3000;
if (c_BrushTypeHatch1_ <= nConstant && c_BrushTypeHatch53_ >= nConstant)
return nConstant + 4000;
if (c_BrushTypeGradient1_ <= nConstant && c_BrushTypeGradient6_ >= nConstant)
return nConstant + 2000 - 61;
return 1000;
}
void ScaleAlpha1( double dScale )
{
long dNewAlpha = long(Alpha1 * dScale + 0.5);
if( dNewAlpha > 255 ) dNewAlpha = 255;
else if( dNewAlpha < 0 ) dNewAlpha = 0;
Alpha1 = dNewAlpha;
}
void ScaleAlpha2( double dScale )
{
long dNewAlpha = long(Alpha2 * dScale + 0.5);
if( dNewAlpha > 255 ) dNewAlpha = 255;
else if( dNewAlpha < 0 ) dNewAlpha = 0;
Alpha2 = dNewAlpha;
}
void ScaleTextureAlpha( double dScale )
{
long dNewAlpha = long(TextureAlpha * dScale + 0.5);
if( dNewAlpha > 255 ) dNewAlpha = 255;
else if( dNewAlpha < 0 ) dNewAlpha = 0;
TextureAlpha = dNewAlpha;
}
BOOL IsEqual(CBrush* pBrush)
{
if (NULL == pBrush)
return FALSE;
/*return ((Type == pBrush->Type) &&
(Color1 == pBrush->Color1) && (Color2 == pBrush->Color2) &&
(Alpha1 == pBrush->Alpha1) && (Alpha2 == pBrush->Alpha2));*/
return ((Type == pBrush->Type) &&
(Color1 == pBrush->Color1) && (Color2 == pBrush->Color2) &&
(Alpha1 == pBrush->Alpha1) && (Alpha2 == pBrush->Alpha2) && (LinearAngle == pBrush->LinearAngle) &&
(TexturePath == pBrush->TexturePath) && (TextureAlpha == pBrush->TextureAlpha) && (TextureMode == pBrush->TextureMode) &&
(Rectable == pBrush->Rectable) && (Rect.Equals(pBrush->Rect)));
}
void SetDefaultParams()
{
Type = c_BrushTypeSolid;
Color1 = 0;
Alpha1 = 255;
Color2 = 0;
Alpha2 = 255;
TextureAlpha = 255;
TextureMode = c_BrushTextureModeStretch;
LinearAngle = 0;
TexturePath = _T("");
Rectable = FALSE;
Rect.X = 0.0F;
Rect.Y = 0.0F;
Rect.Width = 0.0F;
Rect.Height = 0.0F;
}
public:
CBrush()
{
SetDefaultParams();
}
CBrush( const CBrush& other )
{
Type = other.Type;
Color1 = other.Color1;
Alpha1 = other.Alpha1;
Color2 = other.Color2;
Alpha2 = other.Alpha2;
TexturePath = other.TexturePath;
TextureAlpha = other.TextureAlpha;
TextureMode = other.TextureMode;
Rectable = other.Rectable;
Rect = other.Rect;
LinearAngle = other.LinearAngle;
}
CBrush& operator=(const CBrush& other)
{
Type = other.Type;
Color1 = other.Color1;
Alpha1 = other.Alpha1;
Color2 = other.Color2;
Alpha2 = other.Alpha2;
TexturePath = other.TexturePath;
TextureAlpha = other.TextureAlpha;
TextureMode = other.TextureMode;
Rectable = other.Rectable;
Rect = other.Rect;
LinearAngle = other.LinearAngle;
return *this;
}
virtual ~CBrush()
{
}
BOOL IsTexture()
{
return (c_BrushTypeTexture == Type);
}
BOOL IsOneColor()
{
return (c_BrushTypeSolid == Type);
}
BOOL IsTwoColor()
{
return ((c_BrushTypeHorizontal <= Type && c_BrushTypeCylinderVer >= Type) ||
(c_BrushTypeHatch1 <= Type && c_BrushTypeHatch53 >= Type));
}
void SetToRenderer(IAVSRenderer *pRenderer)
{
Type = ConstantCompatible(Type);
pRenderer->put_BrushType(Type);
if (IsOneColor())
{
pRenderer->put_BrushColor1(Color1);
pRenderer->put_BrushAlpha1(Alpha1);
}
else if (IsTexture())
{
BSTR bstrTexturePath = TexturePath.AllocSysString();
pRenderer->put_BrushTexturePath(bstrTexturePath);
SysFreeString(bstrTexturePath);
pRenderer->put_BrushTextureMode(TextureMode);
pRenderer->put_BrushTextureAlpha(TextureAlpha);
pRenderer->BrushRect(Rectable, Rect.X, Rect.Y, Rect.Width, Rect.Height);
}
else if (IsTwoColor())
{
pRenderer->put_BrushColor1(Color1);
pRenderer->put_BrushAlpha1(Alpha1);
pRenderer->put_BrushColor2(Color2);
pRenderer->put_BrushAlpha2(Alpha2);
}
}
};
class CFont
{
public:
CString Path;
CString Name;
double Size;
BOOL Bold;
BOOL Italic;
byte Underline;
byte Strikeout;
BOOL StringGID;
double CharSpace;
public:
CString ToXmlString(CString strRootNodeName = _T("font"), BOOL bAttributed = TRUE)
{
XmlUtils::CXmlWriter oXmlWriter;
if (!bAttributed)
{
oXmlWriter.WriteNodeBegin(strRootNodeName);
oXmlWriter.WriteNode(_T("name"), Name);
oXmlWriter.WriteNode(_T("size"), Size);
oXmlWriter.WriteNode(_T("bold"), Bold);
oXmlWriter.WriteNode(_T("italic"), Italic);
oXmlWriter.WriteNode(_T("underline"), Underline);
oXmlWriter.WriteNode(_T("strikeout"), Strikeout);
oXmlWriter.WriteNode(_T("path"), Path);
oXmlWriter.WriteNode(_T("gid"), StringGID);
oXmlWriter.WriteNodeEnd(strRootNodeName);
}
else
{
oXmlWriter.WriteNodeBegin(strRootNodeName, TRUE);
ToXmlAttributes(oXmlWriter);
oXmlWriter.WriteNodeEnd(strRootNodeName, TRUE);
}
return oXmlWriter.GetXmlString();
}
void FromXmlString(CString& strXml)
{
XmlUtils::CXmlReader oXmlReader;
oXmlReader.SetXmlString(strXml);
oXmlReader.ReadRootNode();
FromXmlAttributes(oXmlReader);
}
void ToXmlAttributes(XmlUtils::CXmlWriter& oXmlWriter)
{
oXmlWriter.WriteAttribute(_T("name"), Name);
oXmlWriter.WriteAttribute(_T("size"), Size);
oXmlWriter.WriteAttribute(_T("bold"), Bold);
oXmlWriter.WriteAttribute(_T("italic"), Italic);
oXmlWriter.WriteAttribute(_T("underline"), Underline);
oXmlWriter.WriteAttribute(_T("strikeout"), Strikeout);
oXmlWriter.WriteAttribute(_T("path"), Path);
oXmlWriter.WriteAttribute(_T("gid"), StringGID);
}
void FromXmlAttributes(XmlUtils::CXmlReader& oXmlReader)
{
Name = oXmlReader.ReadNodeAttributeOrValue(_T("name"), _T("Arial"));
Size = XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("size"), _T("0")));
Bold = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("bold"), _T("0")));
Italic = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("italic"), _T("0")));
Underline = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("underline"), _T("0")));
Strikeout = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("strikeout"), _T("0")));
Path = oXmlReader.ReadNodeAttributeOrValue(_T("path"), _T(""));
StringGID = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("gid"), _T("0")));
}
void FromXmlNode(XmlUtils::CXmlNode& oXmlNode)
{
Name = oXmlNode.GetAttributeOrValue(_T("name"), _T("Arial"));
Size = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("size"), _T("0")));
Bold = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("bold"), _T("0")));
Italic = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("italic"), _T("0")));
Underline = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("underline"), _T("0")));
Strikeout = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("strikeout"), _T("0")));
Path = oXmlNode.GetAttributeOrValue(_T("path"), _T(""));
StringGID = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("gid"), _T("0")));
}
void FromXmlNode2(XmlUtils::CXmlNode& oXmlNode)
{
Name = oXmlNode.GetAttributeOrValue(_T("font-name"), _T("Arial"));
Size = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("font-size"), _T("0")));
Bold = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("font-bold"), _T("0")));
Italic = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("font-italic"), _T("0")));
Underline = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("font-underline"), _T("0")));
Strikeout = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("font-strikeout"), _T("0")));
Path = oXmlNode.GetAttributeOrValue(_T("font-path"), _T(""));
StringGID = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("font-gid"), _T("0")));
}
BOOL IsEqual(CFont* pFont)
{
if (NULL == pFont)
return FALSE;
if (!Path.IsEmpty() && !pFont->Path.IsEmpty())
return ((Path == pFont->Path) && (StringGID == pFont->StringGID) && (Size == pFont->Size) && (Bold == pFont->Bold) && (Italic == pFont->Italic));
return ((Name == pFont->Name) && (Path == pFont->Path) && (StringGID == pFont->StringGID) && (Size == pFont->Size) &&
(Bold == pFont->Bold) && (Italic == pFont->Italic) &&
(Underline == pFont->Underline) && (Strikeout == pFont->Strikeout));
}
BOOL IsEqual2(CFont* pFont, double dScalingSrcSize = 1)
{
if (NULL == pFont)
return FALSE;
if (!Path.IsEmpty() && !pFont->Path.IsEmpty())
return ((Path == pFont->Path) && (StringGID == pFont->StringGID) && (Size == (pFont->Size * dScalingSrcSize)) && (Bold == pFont->Bold) && (Italic == pFont->Italic));
return ((Name == pFont->Name) && (Path == pFont->Path) && (StringGID == pFont->StringGID) && (Size == (pFont->Size * dScalingSrcSize)) &&
(Bold == pFont->Bold) && (Italic == pFont->Italic));
}
BOOL IsEqual3(CFont* pFont)
{
if (NULL == pFont)
return FALSE;
return ((Path == pFont->Path) && (Bold == pFont->Bold) && (Italic == pFont->Italic));
}
BOOL IsEqual4(CFont* pFont)
{
if (NULL == pFont)
return FALSE;
return ((Name == pFont->Name) && (Bold == pFont->Bold) && (Italic == pFont->Italic));
}
LONG GetStyle() const
{
LONG lStyle = 0;
if (Bold)
lStyle |= 0x01;
if (Italic)
lStyle |= 0x02;
lStyle |= Underline << 2;
lStyle |= Strikeout << 7;
return lStyle;
}
void SetStyle(LONG const& lStyle)
{
Bold = (0x01 == (0x01 & lStyle));
Italic = (0x02 == (0x02 & lStyle));
Underline = (byte)(0x7C & lStyle) >> 2;
Strikeout = (byte)(0x0180 & lStyle) >> 7;
}
void SetToRenderer(IAVSRenderer *pRenderer)
{
BSTR bstrName = Name.AllocSysString();
pRenderer->put_FontName(bstrName);
SysFreeString(bstrName);
BSTR bstrPath = Path.AllocSysString();
pRenderer->put_FontPath(bstrPath);
SysFreeString(bstrPath);
pRenderer->put_FontSize(Size);
pRenderer->put_FontStyle(GetStyle());
pRenderer->put_FontStringGID(StringGID);
pRenderer->put_FontCharSpace(CharSpace);
}
void SetDefaultParams()
{
Name = _T("Arial");
Path = _T("");
Size = 0;
Bold = FALSE;
Italic = FALSE;
Underline = 0;
Strikeout = 0;
StringGID = FALSE;
CharSpace = 0.0;
}
public:
CFont()
{
SetDefaultParams();
}
CFont( const CFont& other )
{
*this = other;
}
CFont& operator=(const CFont& other)
{
Name = other.Name;
Path = other.Path;
Size = other.Size;
Bold = other.Bold;
Italic = other.Italic;
Underline = other.Underline;
Strikeout = other.Strikeout;
StringGID = other.StringGID;
CharSpace = other.CharSpace;
return *this;
}
virtual ~CFont()
{
}
};
class CFormat
{
public:
BOOL AntiAliasPen;
BOOL AntiAliasBrush;
BOOL AntiAliasText;
long StringAlignmentVertical;
long StringAlignmentHorizontal;
BOOL WordWrapBySymbol;
long ImageAlphMode;
public:
CString ToXmlString(CString strRootNodeName = _T("format"), BOOL bAttributed = FALSE)
{
XmlUtils::CXmlWriter oXmlWriter;
if (!bAttributed)
{
oXmlWriter.WriteNodeBegin(strRootNodeName);
oXmlWriter.WriteNode(_T("antialiaspen"), AntiAliasPen);
oXmlWriter.WriteNode(_T("antialiasbrush"), AntiAliasBrush);
oXmlWriter.WriteNode(_T("antialiastext"), AntiAliasText);
oXmlWriter.WriteNode(_T("stringalignmentvertical"), StringAlignmentVertical);
oXmlWriter.WriteNode(_T("stringalignmenthorizontal"), StringAlignmentHorizontal);
oXmlWriter.WriteNode(_T("wordwrapbysymbol"), WordWrapBySymbol);
oXmlWriter.WriteNode(_T("imagealphmode"), ImageAlphMode);
oXmlWriter.WriteNodeEnd(strRootNodeName);
}
else
{
oXmlWriter.WriteNodeBegin(strRootNodeName, TRUE);
ToXmlAttributes(oXmlWriter);
oXmlWriter.WriteNodeEnd(strRootNodeName, TRUE);
}
return oXmlWriter.GetXmlString();
}
void FromXmlString(CString strXml)
{
XmlUtils::CXmlReader oXmlReader;
oXmlReader.SetXmlString(strXml);
oXmlReader.ReadRootNode();
FromXmlAttributes(oXmlReader);
}
void ToXmlAttributes(XmlUtils::CXmlWriter& oXmlWriter)
{
oXmlWriter.WriteAttribute(_T("antialiaspen"), AntiAliasPen);
oXmlWriter.WriteAttribute(_T("antialiasbrush"), AntiAliasBrush);
oXmlWriter.WriteAttribute(_T("antialiastext"), AntiAliasText);
oXmlWriter.WriteAttribute(_T("stringalignmentvertical"), StringAlignmentVertical);
oXmlWriter.WriteAttribute(_T("stringalignmenthorizontal"), StringAlignmentHorizontal);
oXmlWriter.WriteAttribute(_T("wordwrapbysymbol"), WordWrapBySymbol);
oXmlWriter.WriteAttribute(_T("imagealphmode"), ImageAlphMode);
}
void FromXmlAttributes(XmlUtils::CXmlReader& oXmlReader)
{
AntiAliasPen = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("antialiaspen"), _T("1")));
AntiAliasBrush = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("antialiasbrush"), _T("1")));
AntiAliasText = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("antialiastext"), _T("0")));
StringAlignmentVertical = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("stringalignmentvertical"), _T("0")));
StringAlignmentHorizontal = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("stringalignmenthorizontal"), _T("0")));
WordWrapBySymbol = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("wordwrapbysymbol"), _T("0")));
ImageAlphMode = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("imagealphmode"), _T("0")));
}
void FromXmlNode(XmlUtils::CXmlNode& oXmlNode)
{
AntiAliasPen = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("antialiaspen"), _T("1")));
AntiAliasBrush = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("antialiasbrush"), _T("1")));
AntiAliasText = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("antialiastext"), _T("0")));
StringAlignmentVertical = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("font-stringalignmentvertical"), _T("1")));
StringAlignmentHorizontal = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("font-stringalignmenthorizontal"), _T("1")));
WordWrapBySymbol = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("wordwrapbysymbol"), _T("0")));
ImageAlphMode = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("imagealphmode"), _T("0")));
}
public:
CFormat()
{
AntiAliasPen = TRUE;
AntiAliasBrush = TRUE;
AntiAliasText = TRUE;
StringAlignmentVertical = 0;
StringAlignmentHorizontal = 0;
WordWrapBySymbol = FALSE;
ImageAlphMode = 0;
}
CFormat( const CFormat& other )
{
AntiAliasPen = other.AntiAliasPen;
AntiAliasBrush = other.AntiAliasBrush;
AntiAliasText = other.AntiAliasText;
StringAlignmentVertical = other.StringAlignmentVertical;
StringAlignmentHorizontal = other.StringAlignmentHorizontal;
WordWrapBySymbol = other.WordWrapBySymbol;
ImageAlphMode = other.ImageAlphMode;
}
CFormat& operator=(const CFormat& other)
{
AntiAliasPen = other.AntiAliasPen;
AntiAliasBrush = other.AntiAliasBrush;
AntiAliasText = other.AntiAliasText;
StringAlignmentVertical = other.StringAlignmentVertical;
StringAlignmentHorizontal = other.StringAlignmentHorizontal;
WordWrapBySymbol = other.WordWrapBySymbol;
ImageAlphMode = other.ImageAlphMode;
return *this;
}
~CFormat()
{
}
};
class CShadow
{
public:
BOOL Visible;
double DistanceX;
double DistanceY;
double BlurSize;
long Color;
long Alpha;
public:
CString ToXmlString(CString strRootNodeName = _T("shadow"), BOOL bAttributed = FALSE)
{
XmlUtils::CXmlWriter oXmlWriter;
if (!bAttributed)
{
oXmlWriter.WriteNodeBegin(strRootNodeName);
oXmlWriter.WriteNode(_T("visible"), Visible);
oXmlWriter.WriteNode(_T("distancex"), DistanceX);
oXmlWriter.WriteNode(_T("distancey"), DistanceY);
oXmlWriter.WriteNode(_T("blursize"), BlurSize);
oXmlWriter.WriteNode(_T("color"), Color);
oXmlWriter.WriteNode(_T("alpha"), Alpha);
oXmlWriter.WriteNodeEnd(strRootNodeName);
}
else
{
oXmlWriter.WriteNodeBegin(strRootNodeName, TRUE);
ToXmlAttributes(oXmlWriter);
oXmlWriter.WriteNodeEnd(strRootNodeName, TRUE);
}
return oXmlWriter.GetXmlString();
}
void FromXmlString(CString& strXml)
{
XmlUtils::CXmlReader oXmlReader;
oXmlReader.SetXmlString(strXml);
oXmlReader.ReadRootNode();
FromXmlAttributes(oXmlReader);
}
void ToXmlAttributes(XmlUtils::CXmlWriter& oXmlWriter)
{
oXmlWriter.WriteAttribute(_T("visible"), Visible);
oXmlWriter.WriteAttribute(_T("distancex"), DistanceX);
oXmlWriter.WriteAttribute(_T("distancey"), DistanceY);
oXmlWriter.WriteAttribute(_T("blursize"), BlurSize);
oXmlWriter.WriteAttribute(_T("color"), Color);
oXmlWriter.WriteAttribute(_T("alpha"), Alpha);
}
void FromXmlAttributes(XmlUtils::CXmlReader& oXmlReader)
{
Visible = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("visible"), _T("0")));
DistanceX = XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("distancex"), _T("0")));
DistanceY = XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("distancey"), _T("0")));
BlurSize = XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("blursize"), _T("0")));
Color = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("color"), _T("0")));
Alpha = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("alpha"), _T("0")));
}
void FromXmlNode(XmlUtils::CXmlNode& oXmlNode)
{
Visible = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("visible"), _T("0")));
DistanceX = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("distancex"), _T("0")));
DistanceY = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("distancey"), _T("0")));
BlurSize = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("blursize"), _T("0")));
Color = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("color"), _T("0")));
Alpha = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("alpha"), _T("0")));
}
void SetDefaultParams()
{
Visible = FALSE;
DistanceX = 15;
DistanceY = 15;
BlurSize = 0;
Color = 0;
Alpha = 120;
}
public:
CShadow()
{
SetDefaultParams();
}
CShadow( const CShadow& other )
{
Visible = other.Visible;
DistanceX = other.DistanceX;
DistanceY = other.DistanceY;
BlurSize = other.BlurSize;
Color = other.Color;
Alpha = other.Alpha;
}
CShadow& operator=(const CShadow& other)
{
Visible = other.Visible;
DistanceX = other.DistanceX;
DistanceY = other.DistanceY;
BlurSize = other.BlurSize;
Color = other.Color;
Alpha = other.Alpha;
return *this;
}
virtual ~CShadow()
{
}
};
class CBackground
{
public:
long Color;
long Alpha;
public:
CString ToXmlString(CString strRootNodeName = _T("background"), BOOL bAttributed = FALSE)
{
XmlUtils::CXmlWriter oXmlWriter;
if (!bAttributed)
{
oXmlWriter.WriteNodeBegin(strRootNodeName);
oXmlWriter.WriteNode(_T("color"), Color);
oXmlWriter.WriteNode(_T("alpha"), Alpha);
oXmlWriter.WriteNodeEnd(strRootNodeName);
}
else
{
oXmlWriter.WriteNodeBegin(strRootNodeName, TRUE);
ToXmlAttributes(oXmlWriter);
oXmlWriter.WriteNodeEnd(strRootNodeName, TRUE);
}
return oXmlWriter.GetXmlString();
}
void FromXmlString(CString& strXml)
{
XmlUtils::CXmlReader oXmlReader;
oXmlReader.SetXmlString(strXml);
oXmlReader.ReadRootNode();
FromXmlAttributes(oXmlReader);
}
void ToXmlAttributes(XmlUtils::CXmlWriter& oXmlWriter)
{
oXmlWriter.WriteAttribute(_T("color"), Color);
oXmlWriter.WriteAttribute(_T("alpha"), Alpha);
}
void FromXmlAttributes(XmlUtils::CXmlReader& oXmlReader)
{
Color = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("color"), _T("0")));
Alpha = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("alpha"), _T("0")));
}
void FromXmlNode(XmlUtils::CXmlNode& oXmlNode)
{
Color = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("color"), _T("0")));
Alpha = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("alpha"), _T("0")));
}
public:
CBackground()
{
Color = 0;
Alpha = 0;
}
CBackground( const CBackground& other )
{
Color = other.Color;
Alpha = other.Alpha;
}
CBackground& operator=(const CBackground& other)
{
Color = other.Color;
Alpha = other.Alpha;
return *this;
}
virtual ~CBackground()
{
}
};
class CEdgeText
{
public:
long Visible;
double Dist;
long Color;
long Alpha;
public:
CString ToXmlString(CString strRootNodeName = _T("edgetext"), BOOL bAttributed = FALSE)
{
XmlUtils::CXmlWriter oXmlWriter;
if (!bAttributed)
{
oXmlWriter.WriteNodeBegin(strRootNodeName);
oXmlWriter.WriteNode(_T("visible"), Visible);
oXmlWriter.WriteNode(_T("dist"), Dist);
oXmlWriter.WriteNode(_T("color"), Color);
oXmlWriter.WriteNode(_T("alpha"), Alpha);
oXmlWriter.WriteNodeEnd(strRootNodeName);
}
else
{
oXmlWriter.WriteNodeBegin(strRootNodeName, TRUE);
ToXmlAttributes(oXmlWriter);
oXmlWriter.WriteNodeEnd(strRootNodeName, TRUE);
}
return oXmlWriter.GetXmlString();
}
void FromXmlString(CString& strXml)
{
XmlUtils::CXmlReader oXmlReader;
oXmlReader.SetXmlString(strXml);
oXmlReader.ReadRootNode();
FromXmlAttributes(oXmlReader);
}
void ToXmlAttributes(XmlUtils::CXmlWriter& oXmlWriter)
{
oXmlWriter.WriteAttribute(_T("visible"), Visible);
oXmlWriter.WriteAttribute(_T("dist"), Dist);
oXmlWriter.WriteAttribute(_T("color"), Color);
oXmlWriter.WriteAttribute(_T("alpha"), Alpha);
}
void FromXmlAttributes(XmlUtils::CXmlReader& oXmlReader)
{
Visible = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("edge-visible"), _T("0")));
Dist = XmlUtils::GetDouble(oXmlReader.ReadNodeAttributeOrValue(_T("edge-dist"), _T("0")));
Color = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("edge-color"), _T("0")));
Alpha = XmlUtils::GetInteger(oXmlReader.ReadNodeAttributeOrValue(_T("edge-alpha"), _T("0")));
}
void FromXmlNode(XmlUtils::CXmlNode& oXmlNode)
{
Visible = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("edge-visible"), _T("0")));
Dist = XmlUtils::GetDouble(oXmlNode.GetAttributeOrValue(_T("edge-dist"), _T("0")));
Color = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("edge-color"), _T("0")));
Alpha = XmlUtils::GetInteger(oXmlNode.GetAttributeOrValue(_T("edge-alpha"), _T("0")));
}
void SetDefaultParams()
{
Visible = 0;
Dist = 5;
Color = 0;
Alpha = 255;
}
public:
CEdgeText()
{
SetDefaultParams();
}
CEdgeText( const CEdgeText& other )
{
Visible = other.Visible;
Dist = other.Dist;
Color = other.Color;
Alpha = other.Alpha;
}
CEdgeText& operator=(const CEdgeText& other)
{
Visible = other.Visible;
Dist = other.Dist;
Color = other.Color;
Alpha = other.Alpha;
return *this;
}
virtual ~CEdgeText()
{
}
};
static void SetMatrix(Gdiplus::Matrix& oDst, const Gdiplus::Matrix& oSrc)
{
Gdiplus::REAL mass[6];
oSrc.GetElements(mass);
oDst.SetElements(mass[0], mass[1], mass[2], mass[3], mass[4], mass[5]);
}
}
\ No newline at end of file
// EBOOKWriter.cpp : Implementation of CAVSDocxRenderer
#include "stdafx.h"
#include "EBOOKWriter.h"
// CEBOOKWriter
STDMETHODIMP CAVSEBOOKWriter::get_Type(LONG* lType)
{
if (NULL != lType)
*lType = c_nEbookWriter;
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::NewPage()
{
m_dWidth = -1;
m_dHeight = -1;
m_bPageAdded = false;
m_lCommandFlags = 0;
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::get_Height(double* dHeight)
{
*dHeight = m_dHeight;
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::put_Height(double dHeight)
{
m_dHeight = dHeight;
if (0 < m_dWidth && !m_bPageAdded)
{
m_oWriter.BeginPage(m_dWidth, m_dHeight);
m_bPageAdded = true;
}
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::get_Width(double* dWidth)
{
*dWidth = m_dWidth;
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::put_Width(double dWidth)
{
m_dWidth = dWidth;
if (0 < m_dHeight && !m_bPageAdded)
{
m_oWriter.BeginPage(m_dWidth, m_dHeight);
m_bPageAdded = true;
}
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::get_DpiX(double* dDpiX)
{
*dDpiX = m_dDpiX;
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::get_DpiY(double* dDpiY)
{
*dDpiY = m_dDpiY;
return S_OK;
}
/*========================================================================================================*/
// pen --------------------------------------------------------------------------------------
STDMETHODIMP CAVSEBOOKWriter::SetPen(BSTR bsXML)
{
m_oPen.FromXmlString((CString)bsXML);
if (NULL != m_pRenderers)
m_pRenderers->SetPen(bsXML);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_PenColor(LONG* lColor)
{
*lColor = m_oPen.Color;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_PenColor(LONG lColor)
{
m_oPen.Color = lColor;
if (NULL != m_pRenderers)
m_pRenderers->put_PenColor(lColor);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_PenAlpha(LONG* lAlpha)
{
*lAlpha = m_oPen.Alpha;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_PenAlpha(LONG lAlpha)
{
m_oPen.Alpha = lAlpha;
if (NULL != m_pRenderers)
m_pRenderers->put_PenAlpha(lAlpha);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_PenSize(double* dSize)
{
*dSize = m_oPen.Size;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_PenSize(double dSize)
{
m_oPen.Size = dSize;
if (NULL != m_pRenderers)
m_pRenderers->put_PenSize(dSize);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_PenDashStyle(BYTE* val)
{
*val = m_oPen.DashStyle;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_PenDashStyle(BYTE val)
{
m_oPen.DashStyle = val;
if (NULL != m_pRenderers)
m_pRenderers->put_PenDashStyle(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_PenLineStartCap(BYTE* val)
{
*val = m_oPen.LineStartCap;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_PenLineStartCap(BYTE val)
{
m_oPen.LineStartCap = val;
if (NULL != m_pRenderers)
m_pRenderers->put_PenLineStartCap(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_PenLineEndCap(BYTE* val)
{
*val = m_oPen.LineEndCap;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_PenLineEndCap(BYTE val)
{
m_oPen.LineEndCap = val;
if (NULL != m_pRenderers)
m_pRenderers->put_PenLineEndCap(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_PenLineJoin(BYTE* val)
{
*val = m_oPen.LineJoin;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_PenLineJoin(BYTE val)
{
m_oPen.LineJoin = val;
if (NULL != m_pRenderers)
m_pRenderers->put_PenLineJoin(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_PenDashOffset(double* val)
{
*val = m_oPen.DashOffset;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_PenDashOffset(double val)
{
m_oPen.DashOffset = val;
if (NULL != m_pRenderers)
m_pRenderers->put_PenDashOffset(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_PenAlign(LONG* val)
{
*val = m_oPen.Align;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_PenAlign(LONG val)
{
m_oPen.Align = val;
if (NULL != m_pRenderers)
m_pRenderers->put_PenAlign(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_PenMiterLimit(double* val)
{
*val = m_oPen.MiterLimit;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_PenMiterLimit(double val)
{
m_oPen.MiterLimit = val;
if (NULL != m_pRenderers)
m_pRenderers->put_PenMiterLimit(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PenDashPattern(SAFEARRAY* pPattern)
{
if (NULL != pPattern)
{
m_oPen.SetDashPattern((double*)pPattern->pvData, pPattern->rgsabound[0].cElements);
}
if (NULL != m_pRenderers)
m_pRenderers->PenDashPattern(pPattern);
return S_OK;
}
// brush ------------------------------------------------------------------------------------
STDMETHODIMP CAVSEBOOKWriter::SetBrush(BSTR bsXML)
{
m_oBrush.FromXmlString((CString)bsXML);
if (NULL != m_pRenderers)
m_pRenderers->SetBrush(bsXML);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_BrushType(LONG* lType)
{
*lType = m_oBrush.Type;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_BrushType(LONG lType)
{
m_oBrush.Type = lType;
if (NULL != m_pRenderers)
m_pRenderers->put_BrushType(lType);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_BrushColor1(LONG* lColor)
{
*lColor = m_oBrush.Color1;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_BrushColor1(LONG lColor)
{
m_oBrush.Color1 = lColor;
if (NULL != m_pRenderers)
m_pRenderers->put_BrushColor1(lColor);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_BrushAlpha1(LONG* lAlpha)
{
*lAlpha = m_oBrush.Alpha1;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_BrushAlpha1(LONG lAlpha)
{
m_oBrush.Alpha1 = lAlpha;
if (NULL != m_pRenderers)
m_pRenderers->put_BrushAlpha1(lAlpha);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_BrushColor2(LONG* lColor)
{
*lColor = m_oBrush.Color2;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_BrushColor2(LONG lColor)
{
m_oBrush.Color2 = lColor;
if (NULL != m_pRenderers)
m_pRenderers->put_BrushColor2(lColor);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_BrushAlpha2(LONG* lAlpha)
{
*lAlpha = m_oBrush.Alpha2;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_BrushAlpha2(LONG lAlpha)
{
m_oBrush.Alpha2 = lAlpha;
if (NULL != m_pRenderers)
m_pRenderers->put_BrushAlpha2(lAlpha);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_BrushTexturePath(BSTR* bsPath)
{
*bsPath = m_oBrush.TexturePath.AllocSysString();
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_BrushTexturePath(BSTR bsPath)
{
m_oBrush.TexturePath = (CString)bsPath;
if (NULL != m_pRenderers)
m_pRenderers->put_BrushTexturePath(bsPath);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_BrushTextureMode(LONG* lMode)
{
*lMode = m_oBrush.TextureMode;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_BrushTextureMode(LONG lMode)
{
m_oBrush.TextureMode = lMode;
if (NULL != m_pRenderers)
m_pRenderers->put_BrushTextureMode(lMode);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_BrushTextureAlpha(LONG* lTxAlpha)
{
*lTxAlpha = m_oBrush.TextureAlpha;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_BrushTextureAlpha(LONG lTxAlpha)
{
m_oBrush.TextureAlpha = lTxAlpha;
if (NULL != m_pRenderers)
m_pRenderers->put_BrushTextureAlpha(lTxAlpha);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_BrushLinearAngle(double* dAngle)
{
*dAngle = m_oBrush.LinearAngle;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_BrushLinearAngle(double dAngle)
{
m_oBrush.LinearAngle = dAngle;
if (NULL != m_pRenderers)
m_pRenderers->put_BrushLinearAngle(dAngle);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::BrushRect(BOOL val, double left, double top, double width, double height)
{
m_oBrush.Rectable = val;
m_oBrush.Rect.X = (float)left;
m_oBrush.Rect.Y = (float)top;
m_oBrush.Rect.Width = (float)width;
m_oBrush.Rect.Height = (float)height;
if (NULL != m_pRenderers)
m_pRenderers->BrushRect(val, left, top, width, height);
return S_OK;
}
// font -------------------------------------------------------------------------------------
STDMETHODIMP CAVSEBOOKWriter::SetFont(BSTR bsXML)
{
m_oFont.FromXmlString((CString)bsXML);
if (NULL != m_pRenderers)
m_pRenderers->SetFont(bsXML);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_FontName(BSTR* bsName)
{
*bsName = m_oFont.Name.AllocSysString();
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_FontName(BSTR bsName)
{
m_oFont.Name = (CString)bsName;
if (NULL != m_pRenderers)
m_pRenderers->put_FontName(bsName);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_FontPath(BSTR* bsName)
{
*bsName = m_oFont.Path.AllocSysString();
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_FontPath(BSTR bsName)
{
m_oFont.Path = bsName;
if (NULL != m_pRenderers)
m_pRenderers->put_FontPath(bsName);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_FontSize(double* dSize)
{
*dSize = m_oFont.Size;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_FontSize(double dSize)
{
m_oFont.Size = dSize;
if (NULL != m_pRenderers)
m_pRenderers->put_FontSize(dSize);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_FontStyle(LONG* lStyle)
{
*lStyle = m_oFont.GetStyle();
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_FontStyle(LONG lStyle)
{
m_oFont.SetStyle(lStyle);
if (NULL != m_pRenderers)
m_pRenderers->put_FontStyle(lStyle);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_FontStringGID(BOOL* bGID)
{
*bGID = m_oFont.StringGID;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_FontStringGID(BOOL bGID)
{
m_oFont.StringGID = bGID;
if (NULL != m_pRenderers)
m_pRenderers->put_FontStringGID(bGID);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_FontCharSpace(double* dSpace)
{
*dSpace = m_oFont.CharSpace;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_FontCharSpace(double dSpace)
{
m_oFont.CharSpace = dSpace;
if (NULL != m_pRenderers)
m_pRenderers->put_FontCharSpace(dSpace);
return S_OK;
}
// shadow -----------------------------------------------------------------------------------
STDMETHODIMP CAVSEBOOKWriter::SetShadow(BSTR bsXML)
{
m_oShadow.FromXmlString((CString)bsXML);
if (NULL != m_pRenderers)
m_pRenderers->SetShadow(bsXML);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_ShadowDistanceX(double* val)
{
*val = m_oShadow.DistanceX;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_ShadowDistanceX(double val)
{
m_oShadow.DistanceX = val;
if (NULL != m_pRenderers)
m_pRenderers->put_ShadowDistanceX(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_ShadowDistanceY(double* val)
{
*val = m_oShadow.DistanceY;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_ShadowDistanceY(double val)
{
m_oShadow.DistanceY = val;
if (NULL != m_pRenderers)
m_pRenderers->put_ShadowDistanceY(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_ShadowBlurSize(double* val)
{
*val = m_oShadow.BlurSize;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_ShadowBlurSize(double val)
{
m_oShadow.BlurSize = val;
if (NULL != m_pRenderers)
m_pRenderers->put_ShadowBlurSize(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_ShadowColor(LONG* val)
{
*val = m_oShadow.Color;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_ShadowColor(LONG val)
{
m_oShadow.Color = val;
if (NULL != m_pRenderers)
m_pRenderers->put_ShadowColor(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_ShadowAlpha(LONG* val)
{
*val = m_oShadow.Alpha;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_ShadowAlpha(LONG val)
{
m_oShadow.Alpha = val;
if (NULL != m_pRenderers)
m_pRenderers->put_ShadowAlpha(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_ShadowVisible(BOOL* val)
{
*val = m_oShadow.Visible;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_ShadowVisible(BOOL val)
{
m_oShadow.Visible = val;
if (NULL != m_pRenderers)
m_pRenderers->put_ShadowVisible(val);
return S_OK;
}
// edge -------------------------------------------------------------------------------------
STDMETHODIMP CAVSEBOOKWriter::SetEdgeText(BSTR bsXML)
{
m_oEdge.FromXmlString((CString)bsXML);
if (NULL != m_pRenderers)
m_pRenderers->SetEdgeText(bsXML);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_EdgeVisible(LONG* val)
{
*val = m_oEdge.Visible;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_EdgeVisible(LONG val)
{
m_oEdge.Visible = val;
if (NULL != m_pRenderers)
m_pRenderers->put_EdgeVisible(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_EdgeColor(LONG* val)
{
*val = m_oEdge.Color;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_EdgeColor(LONG val)
{
m_oEdge.Color = val;
if (NULL != m_pRenderers)
m_pRenderers->put_EdgeColor(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_EdgeAlpha(LONG* val)
{
*val = m_oEdge.Alpha;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_EdgeAlpha(LONG val)
{
m_oEdge.Alpha = val;
if (NULL != m_pRenderers)
m_pRenderers->put_EdgeAlpha(val);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_EdgeDist(double* val)
{
*val = m_oEdge.Dist;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_EdgeDist(double val)
{
m_oEdge.Dist = val;
if (NULL != m_pRenderers)
m_pRenderers->put_EdgeDist(val);
return S_OK;
}
// ------------------------------------------------------------------------------------------
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::CommandDrawText(BSTR bsText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset)
{
if (!CheckNeedCommands())
return S_OK;
if (c_nHyperlinkType == m_lCurrentCommandType)
return S_OK;
if ((abs(m_dTransformAngle) > 1) || (m_bIsMetafileDrawing == true))
{
PathCommandEnd();
BeginCommand(c_nPathType);
PathCommandText(bsText, fX, fY, fWidth, fHeight, fBaseLineOffset);
DrawPath(c_nWindingFillMode);
EndCommand(c_nPathType);
PathCommandEnd();
return S_OK;
}
double x = fX;
double y = fY;
m_oTransform.TransformPoint(x, y);
double r = fX + fWidth;
double b = fY + fHeight;
m_oTransform.TransformPoint(r, b);
r -= x;
b -= y;
double dInputBaseOffset = fBaseLineOffset;
m_oWriter.WriteText(bsText, NULL, x, y, r, b, fBaseLineOffset);
if (NULL != m_pRenderers)
m_pRenderers->CommandDrawText(bsText, fX, fY, fWidth, fHeight, dInputBaseOffset);
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::CommandDrawTextEx(BSTR bsUnicodeText, BSTR bsGidText, BSTR bsSourceCodeText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset, DWORD lFlags)
{
if (!CheckNeedCommands())
return S_OK;
if ((abs(m_dTransformAngle) > 1) || (m_bIsMetafileDrawing == true))
{
PathCommandEnd();
BeginCommand(c_nPathType);
PathCommandTextEx(bsUnicodeText, bsGidText, bsSourceCodeText, fX, fY, fWidth, fHeight, fBaseLineOffset, lFlags);
DrawPath(c_nWindingFillMode);
EndCommand(c_nPathType);
PathCommandEnd();
return S_OK;
}
double x = fX;
double y = fY;
m_oTransform.TransformPoint(x, y);
double r = fX + fWidth;
double b = fY + fHeight;
m_oTransform.TransformPoint(r, b);
r -= x;
b -= y;
double dInputBaseOffset = fBaseLineOffset;
m_oWriter.WriteText(bsUnicodeText, bsGidText, x, y, r, b, fBaseLineOffset);
if (NULL != m_pRenderers)
m_pRenderers->CommandDrawTextEx(bsUnicodeText, bsGidText, bsSourceCodeText, fX, fY, fWidth, fHeight, dInputBaseOffset, lFlags);
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::BeginCommand(DWORD lType)
{
m_lCurrentCommandType = lType;
SendBeginCommandsToFlags();
if ((c_nShapeGroup == m_lCurrentCommandType) || (c_nShape == m_lCurrentCommandType))
m_oWriter.BeginShape();
if (NULL != m_pRenderers)
m_pRenderers->BeginCommand(lType);
if (!CheckNeedCommands())
return S_OK;
if (c_nImageType == lType)
{
m_bIsMetafileDrawing = true;
}
if (c_nBlock == lType)
{
if (0 == m_lSrcType)
{
NSEBook::CLogicPageDOCX* page = dynamic_cast<NSEBook::CLogicPageDOCX*>(m_oWriter.m_pCurrentPage);
if (NULL != page)
page->BeginParagraph();
}
}
else if (c_nLine == lType)
{
if (0 == m_lSrcType)
{
NSEBook::CLogicPageDOCX* page = dynamic_cast<NSEBook::CLogicPageDOCX*>(m_oWriter.m_pCurrentPage);
if (NULL != page)
page->BeginLine();
}
}
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::EndCommand(DWORD lType)
{
if (NULL != m_pRenderers)
m_pRenderers->EndCommand(lType);
if ((c_nShapeGroup == lType) || (c_nShape == lType))
m_oWriter.EndShape();
if (c_nPageType == lType)
{
m_oWriter.EndPage();
}
SendEndCommandsToFlags(lType);
m_lCurrentCommandType = -1;
if (!CheckNeedCommands())
return S_OK;
if (c_nImageType == lType)
{
m_bIsMetafileDrawing = false;
}
if (c_nBlock == lType)
{
if (0 == m_lSrcType)
{
NSEBook::CLogicPageDOCX* page = dynamic_cast<NSEBook::CLogicPageDOCX*>(m_oWriter.m_pCurrentPage);
if (NULL != page)
page->EndParagraph();
}
}
else if (c_nLine == lType)
{
if (0 == m_lSrcType)
{
NSEBook::CLogicPageDOCX* page = dynamic_cast<NSEBook::CLogicPageDOCX*>(m_oWriter.m_pCurrentPage);
if (NULL != page)
page->EndLine();
}
}
return S_OK;
}
/*========================================================================================================*/
// path commands ----------------------------------------------------------------------------
STDMETHODIMP CAVSEBOOKWriter::PathCommandMoveTo(double fX, double fY)
{
if (!CheckNeedCommands())
return S_OK;
if (c_nSimpleGraphicType == m_lCurrentCommandType)
{
MoveTo(fX, fY);
}
else
{
double x = fX;
double y = fY;
m_oFullTransform.TransformPoint(x, y);
m_pSimpleGraphicsConverter->PathCommandMoveTo(x, y);
if (NULL != m_pRenderers)
m_pRenderers->PathCommandMoveTo(fX, fY);
}
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandLineTo(double fX, double fY)
{
if (!CheckNeedCommands())
return S_OK;
if (c_nSimpleGraphicType == m_lCurrentCommandType)
{
LineTo(fX, fY);
}
else
{
double x = fX;
double y = fY;
m_oFullTransform.TransformPoint(x, y);
m_pSimpleGraphicsConverter->PathCommandLineTo(x, y);
if (NULL != m_pRenderers)
m_pRenderers->PathCommandLineTo(fX, fY);
}
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandLinesTo(SAFEARRAY* pPoints)
{
if (!CheckNeedCommands())
return S_OK;
m_pSimpleGraphicsConverter->PathCommandLinesTo(pPoints);
if (NULL != m_pRenderers)
m_pRenderers->PathCommandLinesTo(pPoints);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandCurveTo(double fX1, double fY1, double fX2, double fY2, double fX3, double fY3)
{
if (!CheckNeedCommands())
return S_OK;
if (c_nSimpleGraphicType == m_lCurrentCommandType)
{
CurveTo(fX1, fY1, fX2, fY2, fX3, fY3);
}
else
{
double x1 = fX1;
double y1 = fY1;
m_oFullTransform.TransformPoint(x1, y1);
double x2 = fX1;
double y2 = fY2;
m_oFullTransform.TransformPoint(x2, y2);
double x3 = fX3;
double y3 = fX3;
m_oFullTransform.TransformPoint(x3, y3);
m_pSimpleGraphicsConverter->PathCommandCurveTo(x1, y1, x2, y2, x3, y3);
if (NULL != m_pRenderers)
m_pRenderers->PathCommandCurveTo(fX1, fY1, fX2, fY2, fX3, fY3);
}
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandCurvesTo(SAFEARRAY* pPoints)
{
if (!CheckNeedCommands())
return S_OK;
m_pSimpleGraphicsConverter->PathCommandCurvesTo(pPoints);
if (NULL != m_pRenderers)
m_pRenderers->PathCommandCurvesTo(pPoints);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandArcTo(double fX, double fY, double fWidth, double fHeight, double fStartAngle, double fSweepAngle)
{
if (!CheckNeedCommands())
return S_OK;
m_pSimpleGraphicsConverter->PathCommandArcTo(fX, fY, fWidth, fHeight, fStartAngle, fSweepAngle);
if (NULL != m_pRenderers)
m_pRenderers->PathCommandArcTo(fX, fY, fWidth, fHeight, fStartAngle, fSweepAngle);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandClose()
{
if (!CheckNeedCommands())
return S_OK;
if (c_nSimpleGraphicType == m_lCurrentCommandType)
{
Close();
}
else
{
m_pSimpleGraphicsConverter->PathCommandClose();
if (NULL != m_pRenderers)
m_pRenderers->PathCommandClose();
}
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandEnd()
{
if (!CheckNeedCommands())
return S_OK;
if (c_nSimpleGraphicType == m_lCurrentCommandType)
{
PathEnd();
}
else
{
m_pSimpleGraphicsConverter->PathCommandEnd();
if (NULL != m_pRenderers)
m_pRenderers->PathCommandEnd();
}
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandStart()
{
if (!CheckNeedCommands())
return S_OK;
if (c_nSimpleGraphicType == m_lCurrentCommandType)
{
PathStart();
}
else
{
m_pSimpleGraphicsConverter->PathCommandStart();
if (NULL != m_pRenderers)
m_pRenderers->PathCommandStart();
}
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandGetCurrentPoint(double* fX, double* fY)
{
if (!CheckNeedCommands())
return S_OK;
m_pSimpleGraphicsConverter->PathCommandGetCurrentPoint(fX, fY);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandText(BSTR bsText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset)
{
if (!CheckNeedCommands())
return S_OK;
_SetFont();
m_pSimpleGraphicsConverter->PathCommandText(bsText, m_pFontManager, fX, fY, fWidth, fHeight, fBaseLineOffset);
if (NULL != m_pRenderers)
m_pRenderers->PathCommandText(bsText, fX, fY, fWidth, fHeight, fBaseLineOffset);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::PathCommandTextEx(BSTR bsUnicodeText, BSTR bsGidText, BSTR bsSourceCodeText, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset, DWORD lFlags)
{
if (!CheckNeedCommands())
return S_OK;
if (NULL != m_pRenderers)
m_pRenderers->PathCommandTextEx(bsUnicodeText, bsGidText, bsSourceCodeText, fX, fY, fWidth, fHeight, fBaseLineOffset, lFlags);
if (NULL != bsGidText)
{
m_oFont.StringGID = TRUE;
return PathCommandText(bsGidText, fX, fY, fWidth, fHeight, fBaseLineOffset);
}
m_oFont.StringGID = FALSE;
return PathCommandText(bsUnicodeText, fX, fY, fWidth, fHeight, fBaseLineOffset);
}
STDMETHODIMP CAVSEBOOKWriter::DrawPath(long nType)
{
if (!CheckNeedCommands())
return S_OK;
if (NULL != m_pRenderers)
m_pRenderers->DrawPath(nType);
m_oWriter.DrawPath(nType);
return S_OK;
}
/*========================================================================================================*/
// transform commands -----------------------------------------------------------------------
STDMETHODIMP CAVSEBOOKWriter::GetCommandParams(double* dAngle, double* dLeft, double* dTop, double* dWidth, double* dHeight, DWORD* lFlags)
{
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::SetCommandParams(double dAngle, double dLeft, double dTop, double dWidth, double dHeight, DWORD lFlags)
{
ApplyTransform2(dAngle, dLeft, dTop, dWidth, dHeight, lFlags);
if (NULL != m_pRenderers)
m_pRenderers->SetCommandParams(dAngle, dLeft, dTop, dWidth, dHeight, lFlags);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::SetTransform(double dA, double dB, double dC, double dD, double dE, double dF)
{
ApplyTransform(dA, dB, dC, dD, dE, dF);
if (NULL != m_pRenderers)
m_pRenderers->SetTransform(dA, dB, dC, dD, dE, dF);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::GetTransform(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF)
{
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::ResetTransform(void)
{
m_oTransform.Reset();
if (NULL != m_pRenderers)
m_pRenderers->ResetTransform();
m_dTransformAngle = 0;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::get_ClipMode(LONG* plMode)
{
*plMode = m_lClipMode;
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::put_ClipMode(LONG lMode)
{
m_lClipMode = lMode;
if (NULL != m_pRenderers)
m_pRenderers->put_ClipMode(lMode);
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::DrawImage(IUnknown* pInterface, double fX, double fY, double fWidth, double fHeight)
{
if (!CheckNeedCommands())
return S_OK;
if (NULL != m_pRenderers)
m_pRenderers->DrawImage(pInterface, fX, fY, fWidth, fHeight);
m_oWriter.WriteImage(pInterface, fX, fY, fWidth, fHeight);
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::DrawImageFromFile(BSTR bstrVal, double fX, double fY, double fWidth, double fHeight)
{
if (!CheckNeedCommands())
return S_OK;
if (NULL != m_pRenderers)
m_pRenderers->DrawImageFromFile(bstrVal, fX, fY, fWidth, fHeight);
m_oWriter.WriteImage((CString)bstrVal, fX, fY, fWidth, fHeight);
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::SetAdditionalParam(BSTR ParamName, VARIANT ParamValue)
{
if (NULL != m_pRenderers)
m_pRenderers->SetAdditionalParam(ParamName, ParamValue);
CString sParamName = ParamName;
if (_T("EffectPainter") == sParamName && VT_UNKNOWN == ParamValue.vt)
{
RELEASEINTERFACE(m_oWriter.m_pPainter);
if (NULL != ParamValue.punkVal)
{
ParamValue.punkVal->QueryInterface(AVSGraphics::IID_IAVSEffectPainter, (void**)&m_oWriter.m_pPainter);
}
}
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::GetAdditionalParam(BSTR ParamName, VARIANT* ParamValue)
{
return S_OK;
}
/*========================================================================================================*/
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::Initialize(BSTR bsXMLOptions)
{
BaseInitialize(bsXMLOptions);
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::SetMetadata(BSTR bsXMLOptions)
{
m_oWriter.m_oFormat.m_oMeta.Clear();
XmlUtils::CXmlNode oNodeMeta;
if (oNodeMeta.FromXmlString((CString)bsXMLOptions))
{
m_oWriter.m_oFormat.m_oMeta.m_strAuthor = oNodeMeta.ReadValueString(_T("author"));
m_oWriter.m_oFormat.m_oMeta.m_strName = oNodeMeta.ReadValueString(_T("name"));
m_oWriter.m_oFormat.m_oMeta.m_strPublisher = oNodeMeta.ReadValueString(_T("publisher"));
m_oWriter.m_bIsSrcCoverExist = (1 == oNodeMeta.ReadValueInt(_T("coverpage")));
XmlUtils::CXmlNode oNodeAnno;
if (oNodeMeta.GetNode(_T("annotation"), oNodeAnno))
{
XmlUtils::CXmlNodes oNodes;
if (oNodeAnno.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)
{
NSEBook::CEbookParagraph* pParagraph = new NSEBook::CEbookParagraph();
pParagraph->m_arLines.AddTail();
NSEBook::CEbookParagraph::CSpan oSpan;
oSpan.m_oText += oNodeS.GetXml();
pParagraph->m_arLines.GetTail().m_listSpans.AddTail(oSpan);
m_oWriter.m_oFormat.m_oMeta.m_listAnnotation.AddTail(pParagraph);
}
else if (_T("p") == sName)
{
NSEBook::CEbookParagraph* pParagraph = new NSEBook::CEbookParagraph();
pParagraph->m_arLines.AddTail();
NSEBook::CEbookParagraph::CSpan oSpan;
oSpan.m_oText += oNodeS.GetText();
pParagraph->m_arLines.GetTail().m_listSpans.AddTail(oSpan);
m_oWriter.m_oFormat.m_oMeta.m_listAnnotation.AddTail(pParagraph);
}
}
}
}
}
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::CreateOfficeFile(BSTR bsFilePath, LONG lFileType)
{
m_lDstType = lFileType;
m_oWriter.m_oFormat.m_oImageManager.m_lDstFormat = m_lDstType;
m_oWriter.m_oFormat.m_oTempManager.m_strTempDirectory = m_strTempDirectory;
m_pRenderers = m_oWriter.CreateDocument(m_lSrcType, m_lDstType);
m_oWriter.SetParametres(&m_oPen, &m_oBrush, &m_oFont, &m_oShadow, &m_oEdge, m_pSimpleGraphicsConverter, &m_oTransform);
m_strDstFilePath = (CString)bsFilePath;
// ----------------cover-------------------------
if (!m_oWriter.m_bIsSrcCoverExist && m_oWriter.m_bIsSaveCover)
{
SaveCover();
}
// ----------------------------------------------
m_oWriter.InitWatermark();
return S_OK;
}
/*========================================================================================================*/
STDMETHODIMP CAVSEBOOKWriter::CloseFile()
{
m_oWriter.EndFile();
if (false)
m_oWriter.m_oFormat.SaveToFile(m_oWriter.m_oFormat.m_oTempManager.m_strTempDirectory + _T("\\format.xml"));
if (_T("") == m_oWriter.m_oFormat.m_oMeta.m_strName)
{
CString strName = m_strDstFilePath;
int nEnd = strName.ReverseFind(TCHAR('.'));
int nStr1 = strName.ReverseFind(TCHAR('\\'));
int nStr2 = strName.ReverseFind(TCHAR('/'));
int nStr = max(nStr1, nStr2);
if ((-1 != nStr) && (-1 != nEnd) && (nStr < nEnd))
{
m_oWriter.m_oFormat.m_oMeta.m_strName = strName.Mid(nStr + 1, nEnd - nStr - 1);
}
}
switch (m_lDstType)
{
case 0:
{
NSEBook::CWriter_Epub epub;
epub.CreateDocument(&m_oWriter);
epub.CloseFile(m_strDstFilePath, &m_oWriter);
break;
}
case 1:
{
NSEBook::CWriter_Fb2 fb2;
fb2.CreateDocument(&m_oWriter);
fb2.CloseFile(m_strDstFilePath, &m_oWriter);
break;
}
case 2:
{
NSEBook::CWriter_Mobi mobi;
mobi.CreateDocument(&m_oWriter);
mobi.CloseFile(m_strDstFilePath, &m_oWriter);
break;
}
case 3:
{
NSEBook::CWriter_Docx docx;
docx.CreateDocument(&m_oWriter);
docx.CloseFile(m_strDstFilePath, &m_oWriter);
break;
}
default:
break;
}
m_oWriter.CloseFile();
return S_OK;
}
/*========================================================================================================*/
// AVSRenderer2
STDMETHODIMP CAVSEBOOKWriter::CommandLong(LONG lCommand)
{
if (lCommand == c_nPageBreak)
{
if (NULL != m_oWriter.m_pCurrentPage)
{
m_oWriter.m_pCurrentPage->WritePagePreak();
}
}
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::CommandDouble(double dCommand)
{
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::CommandString(BSTR bsCommand)
{
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::CommandVariant(VARIANT vCommand)
{
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::CommandLong2(LONG lType, LONG lCommand)
{
if (c_nBlockHeadingLevel == lType)
{
NSEBook::CLogicPageDOCX* page = dynamic_cast<NSEBook::CLogicPageDOCX*>(m_oWriter.m_pCurrentPage);
if (NULL != page)
page->SetParagraphStyle(lCommand);
}
else if (c_nBlockNumberingLevel == lType)
{
NSEBook::CLogicPageDOCX* page = dynamic_cast<NSEBook::CLogicPageDOCX*>(m_oWriter.m_pCurrentPage);
if (NULL != page)
page->SetParagraphNumLevel(lCommand);
}
else if (c_nBaselineShift == lType)
{
NSEBook::CLogicPageDOCX* page = dynamic_cast<NSEBook::CLogicPageDOCX*>(m_oWriter.m_pCurrentPage);
if (NULL != page)
page->SetBaselineOffset((double)lCommand);
}
else if (c_nBlockHorzAlign == lType)
{
NSEBook::CLogicPageDOCX* page = dynamic_cast<NSEBook::CLogicPageDOCX*>(m_oWriter.m_pCurrentPage);
if (NULL != page)
page->SetParTextAlign(lCommand);
}
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::CommandDouble2(LONG lType, double dCommand)
{
if (c_nTableTop == lType)
{
NSEBook::CLogicPageDOCX* page = dynamic_cast<NSEBook::CLogicPageDOCX*>(m_oWriter.m_pCurrentPage);
if (NULL != page)
page->WriteTableTop(dCommand);
}
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::CommandString2(LONG lType, BSTR bsCommand)
{
if (c_nTableXml == lType)
{
NSEBook::CLogicTable* pTable = new NSEBook::CLogicTable();
pTable->m_bIsEmbeddedFonts = m_oWriter.m_bIsEmbeddedFonts;
pTable->m_lDstFormat = m_lDstType;
pTable->m_pFormat = &m_oWriter.m_oFormat;
pTable->m_pFontManager = &m_oWriter.m_pCurrentPage->m_oFontManager;
pTable->m_pFontsDst = &m_oWriter.m_pCurrentPage->m_oFontsGen;
pTable->LoadFromXml((CString)bsCommand);
m_oWriter.WriteTable(pTable);
}
return S_OK;
}
STDMETHODIMP CAVSEBOOKWriter::CommandVariant2(LONG lType, VARIANT vCommand)
{
return S_OK;
}
\ No newline at end of file
// 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; // ( 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; //
AVSGraphics::IAVSFontManager* m_pFontManager; //
NSCommon::CMatrix m_oBaseTransform; // (: -> )
NSCommon::CMatrix m_oTransform; //
NSCommon::CMatrix m_oFullTransform; // (m_oBaseTransform * m_oTransform)
double m_dTransformAngle;
LONG m_lCurrentCommandType; //
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
// -----------------------------------------------------------------------------
STDMETHOD(get_Type)(LONG* lType);
//-------- --------------------------------------------------
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);
//-------- ----------------------------------------------
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);
//-------- --------------------------------------------------------
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);
//-------- ---------------------------------------------------------------
STDMETHOD(BeginCommand)(DWORD lType);
STDMETHOD(EndCommand)(DWORD lType);
//-------- 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);
//-------- --------------------------------------------------
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"" );
// dpi
int nLOGPIXELSX = 96;
int nLOGPIXELSY = 96;
//
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);
// 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 );
}
};
#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:
// - - . !!!
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:
// - Image .
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))
{
// !
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;
}
};
}
\ No newline at end of file
#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:
//
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;
// ...
m_pBufferMem = m_pBuffer;
// , , ...
// ( - (!!!) )
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:
{
// ,
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))
{
// watermark
CEbookGraphicObject* pObject = new CEbookGraphicObject();
pObject->m_oInfo = m_oInfoWatermark;
pObject->m_rcBounds = m_oRectWatermark;
if (0 == oFormat.m_listSections.GetCount())
{
//
oFormat.m_listSections.AddTail();
}
CSection& oSection = oFormat.m_listSections.GetTail();
oSection.m_arItems.AddTail(pObject);
}
m_bIsDumpWatermark = false;
}
};
}
\ No newline at end of file
#pragma once
#include "LogicPagePDF.h"
#include "LogicPageDOCX.h"
\ No newline at end of file
#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;
}
// . m_pFont
m_pFontManager->m_strCurrentPickFont = _T("");
if (0 == width)
{
// ?? ??
m_pFontManager->LoadCurrentFont();
double dOffset = m_pFontManager->m_oFont.m_dBaselineOffsetHTML;
dOffset *= (m_dDpiY / 72.0);
y -= dOffset;
baselineoffset = dOffset;
// .
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)
{
// ,
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)
{
// .
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))
{
// !!!
oSpan.m_oText.AddSpaceFirst();
}
return;
}
//
if (!bIsFontChanged && oTail.m_oBrush.IsEqual(m_pBrush) && !bIsTextDecorationChanged && (oTail.m_dBaselineOffset == dCurrentBaselineOffset))
{
if (c_dSpaceW < abs(oTail.m_dX + oTail.m_dWidthSpan - x))
{
// !!!
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))
{
// !!!
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);
// 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)
{
// 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)
{
// title. -
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)
{
// !!!
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)
{
//
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)
{
// ,
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;
}
};
}
\ No newline at end of file
Binary files a/AVSEBOOKWriter/Logic/LogicPagePDF.h and /dev/null differ Binary files a/AVSEBOOKWriter/Logic/LogicPagePDF.h and /dev/null differ
#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;
}
\ No newline at end of file
#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));
//
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);
//
oHtmlEvents->UnAdvise( piHtmlFile );
RELEASEINTERFACE( oHtmlEvents );
oHtmlEvents2->UnAdvise( piHtmlFile );
RELEASEINTERFACE( oHtmlEvents2 );
}
else
{
OfficeTxtFile::ITxtFilePtr piHtmlFile;
piHtmlFile.CreateInstance(__uuidof(OfficeTxtFile::CTxtFile));
//
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);
//
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;
};
\ No newline at end of file
#pragma once
#include "stdafx.h"
#include "../Writers/Writer.h"
#include "../AVSOfficeUtils/ZLIB/zlib-1.2.3/contrib/minizip/zip.h"
namespace NSMobi
{
class CStream
{
protected:
BYTE* m_pBuffer;
BYTE* m_pBufferMem;
DWORD m_lSize;
public:
CStream()
{
m_pBuffer = 0;
m_pBufferMem = m_pBuffer;
m_lSize = 0;
}
~CStream()
{
RELEASEARRAYOBJECTS(m_pBuffer);
}
AVSINLINE void DestroyNoAttack()
{
m_pBuffer = 0;
m_pBufferMem = m_pBuffer;
m_lSize = 0;
}
AVSINLINE void FromFile(CFile* pFile)
{
m_lSize = (DWORD)pFile->GetFileSize();
m_pBuffer = new BYTE[m_lSize];
m_pBufferMem = m_pBuffer;
pFile->ReadFile(m_pBuffer, m_lSize);
}
AVSINLINE void FromBuffer(BYTE* pData, DWORD size)
{
m_lSize = size;
m_pBuffer = pData;
m_pBufferMem = m_pBuffer;
}
AVSINLINE void CreateFromBuffer(DWORD size)
{
m_lSize = size;
m_pBuffer = new BYTE[m_lSize];
m_pBufferMem = m_pBuffer;
}
AVSINLINE DWORD GetSize()
{
return m_lSize;
}
AVSINLINE BOOL IsValid() const
{
if (m_pBuffer)
return TRUE;
return FALSE;
}
AVSINLINE BYTE* GetBuffer()
{
return m_pBuffer;
}
AVSINLINE void Seek(int nOrigin = 0)
{
m_pBufferMem = m_pBuffer + nOrigin;
}
AVSINLINE void Skip(int nSkip = 0)
{
m_pBufferMem += nSkip;
}
AVSINLINE int GetPosition()
{
return (int)(m_pBufferMem - m_pBuffer);
}
AVSINLINE BYTE* GetData()
{
return m_pBuffer;
}
AVSINLINE BYTE* GetCurrentData()
{
return m_pBufferMem;
}
AVSINLINE BYTE ReadByte()
{
BYTE value = *m_pBufferMem;
m_pBufferMem += sizeof(BYTE);
return value;
}
AVSINLINE short ReadShort()
{
return (short)((ReadByte() << 8) | ReadByte());
}
AVSINLINE USHORT ReadUShort()
{
return (USHORT)((ReadByte() << 8) | ReadByte());
}
AVSINLINE long ReadLong()
{
return (long)((ReadByte() << 24) | (ReadByte() << 16) | (ReadByte() << 8) | ReadByte());
}
AVSINLINE DWORD ReadDWORD()
{
return (DWORD)((ReadByte() << 24) | (ReadByte() << 16) | (ReadByte() << 8) | ReadByte());
}
AVSINLINE ULONG64 ReadULONG64()
{
return (ULONG64)((ReadDWORD() * 0x0100000000) | ReadDWORD());
}
AVSINLINE double ReadDouble()
{
double value = *(double*)(m_pBufferMem);
m_pBufferMem += sizeof(double);
return value;
}
AVSINLINE float ReadFloat()
{
float value = *(float*)(m_pBufferMem);
m_pBufferMem += sizeof(float);
return value;
}
AVSINLINE CString ReadStringW(int nLen = -1)
{
if (-1 != nLen)
{
CString strRet((WCHAR*)m_pBufferMem, nLen);
m_pBufferMem += nLen * sizeof(WCHAR);
return strRet;
}
return _T("");
}
AVSINLINE CString ReadStringA(int nLen = -1)
{
if (-1 != nLen)
{
CString strRet((CHAR*)m_pBufferMem, nLen);
m_pBufferMem += nLen * sizeof(CHAR);
return strRet;
}
return _T("");
}
AVSINLINE CString ReadStringUTF8(int nLen = -1)
{
if (-1 != nLen)
{
CString strRet = CFile::GetCStringFromUTF8(m_pBufferMem, nLen);
m_pBufferMem += nLen;
return strRet;
}
return _T("");
}
AVSINLINE void WriteByte(const BYTE& val)
{
*m_pBufferMem = val;
++m_pBufferMem;
}
AVSINLINE void WriteUShort(const USHORT& val)
{
*m_pBufferMem = (BYTE)(val >> 8);
++m_pBufferMem;
*m_pBufferMem = (BYTE)val;
++m_pBufferMem;
}
AVSINLINE void WriteLong(const LONG& val)
{
*m_pBufferMem = (BYTE)(val >> 24);
++m_pBufferMem;
*m_pBufferMem = (BYTE)(val >> 16);
++m_pBufferMem;
*m_pBufferMem = (BYTE)(val >> 8);
++m_pBufferMem;
*m_pBufferMem = (BYTE)val;
++m_pBufferMem;
}
AVSINLINE void WriteDWORD(DWORD val)
{
*m_pBufferMem = (BYTE)(val >> 24);
++m_pBufferMem;
*m_pBufferMem = (BYTE)(val >> 16);
++m_pBufferMem;
*m_pBufferMem = (BYTE)(val >> 8);
++m_pBufferMem;
*m_pBufferMem = (BYTE)val;
++m_pBufferMem;
}
AVSINLINE void WriteSet(BYTE val, LONG lSize)
{
memset(m_pBufferMem, val, lSize);
m_pBufferMem += lSize;
}
AVSINLINE void WriteData(BYTE* pData, LONG lSize)
{
memcpy(m_pBufferMem, pData, lSize);
m_pBufferMem += lSize;
}
AVSINLINE void Write(CStream* pStream)
{
memcpy(m_pBufferMem, pStream->GetData(), pStream->GetPosition());
m_pBufferMem += pStream->GetPosition();
}
AVSINLINE void WriteCStringA(const CStringA& str)
{
CStringA* pStr = const_cast<CStringA*>(&str);
WriteData((BYTE*)pStr->GetBuffer(), str.GetLength());
}
AVSINLINE void DumpToFile(CFile& oFile)
{
oFile.WriteFile((void*)m_pBuffer, GetPosition());
}
};
class CTextDecoder
{
public:
static void PalmDecode(BYTE* pBufferSrc, LONG lSrcLen, BYTE*& pBufferDst, LONG& lDstLen)
{
BYTE* input = (BYTE*)pBufferSrc;
/*BYTE* input = new BYTE[lSrcLen];
for (LONG j = 0; j < lSrcLen; ++j)
{
CHAR charMem = (CHAR)pBufferSrc[j];
input[j] = (charMem < 0) ? (_Byte)(charMem + 256) : (_Byte)charMem;
}*/
int nCurIndexSrc = 0;
int nCurIndexDst = 0;
pBufferDst = new BYTE[max(6000, 8 * lSrcLen)];
BYTE* output = pBufferDst;
BYTE c = 0;
while (nCurIndexSrc < lSrcLen)
{
c = input[nCurIndexSrc++];
if (c >= 1 && c <= 8) // copy 'c' bytes
{
while (c--)
output[nCurIndexDst++] = input[nCurIndexSrc++];
}
else if (c <= 0x7F)
{
// 0, 09-7F = self
output[nCurIndexDst++] = c;
}
else if (c >= 0xC0)
{
// space + ASCII char
output[nCurIndexDst++] = ' ';
output[nCurIndexDst++] = c ^ 0x80;
}
else
{
// 80-BF repeat sequences
USHORT _c = (c << 8) + input[nCurIndexSrc++];
USHORT di = (_c & 0x3FFF) >> 3;
for ( int n = (_c & 7) + 3; ((n--) > 0); ++nCurIndexDst )
output[nCurIndexDst] = output[nCurIndexDst - di];
}
}
//output[nCurIndexDst++] = 0;
lDstLen = nCurIndexDst;
//RELEASEARRAYOBJECTS(input);
}
static bool PalmDoc_memcmp(BYTE* a, BYTE* b, LONG len)
{
/*for (LONG i = 0; i < len; ++i)
{
if (a[i] != b[i])
return false;
}
return true;*/
return (0 == memcmp(a, b, len)) ? true : false;
}
static AVSINLINE LONG PalmDoc_find(BYTE* data, const BYTE& cur, const LONG& pos, const LONG& chunk_len)
{
for (LONG i = pos - chunk_len; i > -1; --i)
{
//if (PalmDoc_memcmp(data + i, data + pos, chunk_len))
// return i;
if (data[i] == cur)
{
BYTE* a = data + i + 1;
BYTE* b = data + pos + 1;
int j = 1;
for (; j < chunk_len; ++j, ++a, ++b)
{
if (*a != *b)
break;
}
if (j == chunk_len)
return i;
}
//if (0 == memcmp(data + i, data + pos, chunk_len))
// return i;
}
return pos;
}
static void PalmEncode(BYTE* pBufferSrc, LONG lSrcLen, BYTE*& pBufferDst, LONG& lDstLen, LONG lLenAll)
{
pBufferDst = new BYTE[2 * lSrcLen + lLenAll - lSrcLen + 2];
BYTE* output = pBufferDst;
LONG i = 0, j = 0, chunk_len = 0, dist = 0;
DWORD compound = 0;
BYTE c = 0, n = 0;
bool found;
BYTE temp[8];
LONG temp_len = 0;
while (i < lSrcLen)
{
c = pBufferSrc[i];
//do repeats
if ( i > 10 && (lSrcLen - i) > 10)
{
found = false;
for (chunk_len = 10; chunk_len > 2; --chunk_len)
{
j = PalmDoc_find(pBufferSrc, c, i, chunk_len);
dist = i - j;
if (j < i && dist <= 2047)
{
found = true;
compound = (dist << 3) + chunk_len - 3;
*(output++) = BYTE(0x80 + (compound >> 8));
*(output++) = BYTE(compound & 0xFF);
i += chunk_len;
break;
}
}
if (found)
continue;
}
//write single character
++i;
if (c == 32 && i < lSrcLen)
{
n = pBufferSrc[i];
if ( n >= 0x40 && n <= 0x7F)
{
*(output++) = BYTE(n^0x80);
++i;
continue;
}
}
if (c == 0 || (c > 8 && c < 0x80))
*(output++) = BYTE(c);
else
{
// Write binary data
j = i;
temp[0] = c;
temp_len = 1;
while (j < lSrcLen && temp_len < 8)
{
c = pBufferSrc[j];
if (c == 0 || (c > 8 && c < 0x80))
break;
temp[temp_len++] = c;
++j;
}
i += temp_len - 1;
*(output++) = (BYTE)temp_len;
for (j = 0; j < temp_len; ++j)
*(output++) = (BYTE)temp[j];
}
}
lDstLen = (LONG)(output - pBufferDst);
LONG lExtraLen = (lLenAll - lSrcLen);
if (lExtraLen > 0)
{
memcpy(output, pBufferSrc + lSrcLen, lExtraLen);
lDstLen += lExtraLen;
output += lExtraLen;
}
if (TRUE)
{
*output = (BYTE)lExtraLen;
++lDstLen;
}
}
public:
static void EncInt(int nValue, bool bForward, int& nLen, BYTE*& pBytes)
{
CAtlArray<BYTE> oArray;
while (true)
{
BYTE b = nValue & 0x7F;
nValue >>= 7; // shift value to the right by 7 bits
oArray.Add(b);
if (nValue == 0)
break;
}
nLen = (int)oArray.GetCount();
if (0 != nLen)
{
if (bForward)
oArray[0] |= 0x80;
else
oArray[nLen - 1] |= 0x80;
}
pBytes = new BYTE[nLen];
for (int i = 0; i < nLen; ++i)
{
pBytes[i] = oArray[nLen - i - 1];
}
}
static void DecInt(int& nValue, int& nLen, bool bForward, BYTE* pBytes, int nSrcLen)
{
nValue = 0;
CAtlArray<BYTE> oArray;
if (bForward)
{
for (int i = 0; i < nSrcLen; ++i)
{
oArray.Add(pBytes[i] & 0x7F);
if (pBytes[i] & 0x80)
break;
}
nLen = (int)oArray.GetCount();
for (int i = 0; i < nLen; ++i)
{
nValue <<= 7;
nValue |= oArray[i];
}
}
else
{
for (int i = nSrcLen - 1; i >= 0; --i)
{
oArray.Add(pBytes[i] & 0x7F);
if (pBytes[i] & 0x80)
break;
}
nLen = (int)oArray.GetCount();
for (int i = nLen - 1; i >= 0; --i)
{
nValue <<= 7;
nValue |= oArray[i];
}
}
}
static void GetTralingData(BYTE* pRecord, DWORD lExtraDataFlag, int& nStart, int& nEnd)
{
DWORD lFlags = lExtraDataFlag >> 1;
int num = 0;
while (lFlags)
{
num += 1;
if (lFlags & 0x01)
{
int sz = 0;
int consumed = 0;
DecInt(sz, consumed, false, pRecord + nStart, nEnd - nStart + 1);
if (sz > consumed)
{
//data[num] = record[-sz:-consumed]
}
nEnd = nEnd - sz;
}
lFlags >>= 1;
}
// Read multibyte chars if any
if (lExtraDataFlag & 0x01)
{
// Only the first two bits are used for the size since there can
// never be more than 3 trailing multibyte chars
int sz = (pRecord[nEnd] & 0x03) + 1;
int consumed = 1;
if (sz > consumed)
{
//data[0] = record[-sz:-consumed];
}
nEnd = nEnd - sz;
}
}
};
class CMobiReader
{
public:
class CPDBHeader
{
public:
CString Name;
USHORT Attributes;
USHORT Version;
DWORD CreationDate;
DWORD ModificationDate;
DWORD LastBackupDate;
DWORD ModificationNumber;
DWORD AppInfoID;
DWORD SortInfoID;
CString Type;
DWORD UniqueIdSeed;
DWORD NextRecordListID;
USHORT NumberOfRecords;
public:
CPDBHeader()
{
Name = _T("");
Attributes = 0;
Version = 0;
CreationDate = 0;
ModificationDate = 0;
LastBackupDate = 0;
ModificationNumber = 0;
AppInfoID = 0;
SortInfoID = 0;
Type = _T("BOOK");
UniqueIdSeed = 0;
NextRecordListID = 0;
NumberOfRecords = 0;
}
~CPDBHeader()
{
}
public:
void ReadFromStream(CStream* pStream)
{
Name = pStream->ReadStringA(32);
Attributes = pStream->ReadUShort();
Version = pStream->ReadUShort();
CreationDate = pStream->ReadDWORD();
ModificationDate = pStream->ReadDWORD();
LastBackupDate = pStream->ReadDWORD();
ModificationNumber = pStream->ReadDWORD();
AppInfoID = pStream->ReadDWORD();
SortInfoID = pStream->ReadDWORD();
Type = pStream->ReadStringA(8);
UniqueIdSeed = pStream->ReadDWORD();
NextRecordListID = pStream->ReadDWORD();
NumberOfRecords = pStream->ReadUShort();
}
void WriteToStream(CStream* pStream, CString& strNameBook, LONG nRecords)
{
// name
CStringA strName = (CStringA)strNameBook;
strName.Replace(' ', '_');
int len = strName.GetLength();
if (31 < len)
{
strName = strName.Mid(0, 31);
len = 31;
}
pStream->WriteCStringA(strName);
for (int i = len; i < 32; ++i)
pStream->WriteByte(0);
//
DWORD dwTime = GetCurrentTime();
pStream->WriteUShort(0);
pStream->WriteUShort(0);
pStream->WriteDWORD(dwTime);
pStream->WriteDWORD(dwTime);
pStream->WriteDWORD(0);
pStream->WriteDWORD(0);
pStream->WriteDWORD(0);
pStream->WriteDWORD(0);
CStringA strType("BOOKMOBI");
pStream->WriteCStringA(strType);
pStream->WriteDWORD((DWORD)(2 * nRecords - 1));
pStream->WriteDWORD(0);
pStream->WriteUShort((USHORT)nRecords);
}
};
class CSectionHeader
{
public:
DWORD Offset;
DWORD Flags;
DWORD Value;
public:
CSectionHeader()
{
Offset = 0;
Flags = 0;
Value = 0;
}
~CSectionHeader()
{
}
AVSINLINE void Read(CStream* pStream)
{
Offset = pStream->ReadDWORD();
Flags = pStream->ReadByte();
BYTE b1 = pStream->ReadByte();
BYTE b2 = pStream->ReadByte();
BYTE b3 = pStream->ReadByte();
Value = b1 << 16 | b2 << 8 | b3;
}
};
class CSection
{
public:
CSectionHeader m_oHeader;
DWORD Length;
public:
CSection()
{
Length = 0;
}
~CSection()
{
}
};
class CHuffmanReader
{
public:
class CDictInfo1
{
public:
BYTE codelen;
BYTE term;
DWORD maxcode;
public:
CDictInfo1()
{
codelen = 0;
term = 0;
maxcode = 0;
}
~CDictInfo1()
{
}
CDictInfo1(const CDictInfo1& oSrc)
{
*this = oSrc;
}
CDictInfo1& operator=(const CDictInfo1& oSrc)
{
codelen = oSrc.codelen;
term = oSrc.term;
maxcode = oSrc.maxcode;
return *this;
}
};
class CDictInfo2
{
public:
USHORT blen;
BYTE* buffer;
public:
CDictInfo2()
{
blen = 0;
buffer = NULL;
}
~CDictInfo2()
{
RELEASEARRAYOBJECTS(buffer);
}
CDictInfo2(const CDictInfo2& oSrc)
{
*this = oSrc;
}
CDictInfo2& operator=(const CDictInfo2& oSrc)
{
blen = oSrc.blen;
buffer = NULL;
if (0 != blen)
{
buffer = new BYTE[blen];
memcpy(buffer, oSrc.buffer, blen);
}
return *this;
}
};
private:
CAtlMap<DWORD, CDictInfo1> m_dict1;
CAtlArray<DWORD> m_mincode;
CAtlArray<DWORD> m_maxcode;
CAtlMap<DWORD, CDictInfo2> m_dict;
public:
CHuffmanReader()
{
}
~CHuffmanReader()
{
}
public:
void LoadTables(CStream* pStream, CSection* pSections, LONG lCountSects)
{
m_dict1.RemoveAll();
m_dict.RemoveAll();
m_mincode.RemoveAll();
m_maxcode.RemoveAll();
if (0 != lCountSects)
LoadHuff(pStream, pSections[0]);
for (LONG i = 1; i < lCountSects; ++i)
LoadCdic(pStream, pSections[i]);
}
void LoadHuff(CStream* pStream, CSection& oSect)
{
pStream->Seek(oSect.m_oHeader.Offset);
CString strId = pStream->ReadStringA(4);
if (_T("HUFF") != strId)
return;
pStream->Skip(4);
DWORD offset1 = pStream->ReadDWORD();
DWORD offset2 = pStream->ReadDWORD();
pStream->Seek(oSect.m_oHeader.Offset + offset1);
for (int i = 0; i < 256; ++i)
{
DWORD dwVal = pStream->ReadDWORD();
CDictInfo1 info;
info.codelen = (BYTE)(dwVal & 0x1F);
info.term = (BYTE)(dwVal & 0x80);
info.maxcode = dwVal >> 8;
info.maxcode = ((info.maxcode + 1) << (32 - info.codelen)) - 1;
m_dict1.SetAt(dwVal, info);
}
pStream->Seek(oSect.m_oHeader.Offset + offset2);
DWORD dict2[64];
for (int i = 0; i < 64; ++i)
dict2[i] = pStream->ReadDWORD();
m_mincode.Add(0);
m_maxcode.Add(0xFFFFFFFF);
for (int i = 0; i < 64; i += 2)
{
DWORD value = dict2[i] << (32 - i / 2);
m_mincode.Add(value);
}
for (int i = 1; i < 64; i += 2)
{
DWORD value = dict2[i] << (32 - i / 2);
m_maxcode.Add(value);
}
}
void LoadCdic(CStream* pStream, CSection& oSect)
{
pStream->Seek(oSect.m_oHeader.Offset);
CString strId = pStream->ReadStringA(4);
if (_T("CDIC") != strId)
return;
pStream->Skip(4);
DWORD phrases = pStream->ReadDWORD();
DWORD bits = pStream->ReadDWORD();
int n = min((int)1 << bits, (int)(phrases - m_dict.GetCount()));
for (int i = 0; i < n; ++i)
{
USHORT value = pStream->ReadUShort();
int pos = pStream->GetPosition();
CDictInfo2 info;
pStream->Seek(16 + value);
info.blen = pStream->ReadUShort();
info.blen &= 0x8000;
info.buffer = new BYTE[info.blen];
memcpy(info.buffer, pStream->GetCurrentData(), info.blen);
pStream->Seek(pos);
m_dict.SetAt(value, info);
}
}
void Decode(BYTE* pBufferSrc, LONG lCountSrc, BYTE*& pBufferDst, LONG& lCountDst)
{
LONG bitsleft = lCountSrc * 8;
BYTE* data = new BYTE[lCountSrc + 8];
memcpy(data, pBufferSrc, lCountSrc);
memset(data + lCountSrc, 0x00, 8);
CStream oStream;
oStream.FromBuffer(data, lCountSrc + 8);
CBufferedText oBufferedText;
int pos = 0;
ULONG64 x = oStream.ReadDWORD();
int n = 32;
while (true)
{
if (n <= 0)
{
pos += 4;
oStream.Seek(pos);
x = oStream.ReadULONG64();
n += 32;
}
DWORD code = (DWORD)((x >> n) & 0xFFFFFFFF);
CAtlMap<DWORD, CDictInfo1>::CPair* pPair1 = m_dict1.Lookup(code >> 24);
if (NULL == pPair1)
break;
CDictInfo1 info1 = pPair1->m_value;
DWORD max_code = 0;
if (!info1.term)
{
while (code < m_mincode[info1.codelen])
info1.codelen += 1;
max_code = m_maxcode[info1.codelen];
}
n -= info1.codelen;
bitsleft -= info1.codelen;
if (bitsleft < 0)
break;
DWORD r = (max_code - code) >> (32 - info1.codelen);
CAtlMap<DWORD, CDictInfo2>::CPair* pPair2 = m_dict.Lookup(r);
if (NULL == pPair2)
break;
if (!pPair2->m_value.blen)
{
pPair2->m_value.blen = 1;
}
oBufferedText.WriteData(pPair2->m_value.buffer, pPair2->m_value.blen);
}
oStream.DestroyNoAttack();
lCountDst = (LONG)oBufferedText.GetCurSize();
pBufferDst = new BYTE[lCountDst];
memcpy(pBufferDst, oBufferedText.GetData(), lCountDst);
}
};
class CEXTHRecord
{
public:
enum E_EXTHRecord
{
exthDRMServerId = 1,
exthDRMCommerceID = 2,
exthDRMEbookID = 3,
exthAuthor = 100,
exthPublisher = 101,
exthImpirit = 102,
exthDescription = 103,
exthIsbn = 104,
exthSubject = 105,
exthPublishingDate = 106,
exthReview = 107,
exthContributor = 108,
exthRights = 109,
exthSubjectCode = 110,
exthType = 111,
exthSource = 112,
exthAsin = 113,
exthVersionNumber = 114,
exthSample = 115,
exthStartReading = 116,
exthAdult = 117,
exthRetailPrice = 118,
exthRetailPriceCurrency = 119,
exthDictShortName = 200,
exthCoverOffset = 201,
exthThumbOffset = 202,
exthHasFakeCover = 203,
exthCreatorSoftware = 204,
exthCreatorMajorVersion = 205,
exthCreatorMinorVersion = 206,
exthCreatorBuildNumber = 207,
exthWatermark = 208,
exthTamperProofKeys = 209,
exthFontSignature = 300,
exthClippingLimit = 401,
exthPublisherLimit = 402,
exthTTS = 404,
exthCdEtype = 501,
exthLastUpdateTime = 502,
exthUpdateTitle = 503,
exthUnknown = 1000
};
E_EXTHRecord m_eType;
DWORD m_dwValue;
CString m_strValue;
public:
CEXTHRecord()
{
m_eType = exthUnknown;
m_dwValue = 0;
m_strValue = _T("");
}
~CEXTHRecord()
{
}
AVSINLINE void Read(CStream* pStream)
{
m_eType = (E_EXTHRecord)pStream->ReadDWORD();
DWORD dwLength = pStream->ReadDWORD();
if (12 == dwLength)
{
m_dwValue = pStream->ReadDWORD();
}
else
{
m_strValue = pStream->ReadStringUTF8(dwLength - 8);
}
}
};
class CEXTHHeader
{
public:
CString m_strType;
CAtlArray<CEXTHRecord> m_arRecords;
public:
CEXTHHeader() : m_arRecords()
{
m_strType = _T("");
}
~CEXTHHeader()
{
}
AVSINLINE void Read(CStream* pStream)
{
int pos1 = pStream->GetPosition();
m_strType = pStream->ReadStringA(4);
DWORD dwSize = pStream->ReadDWORD();
DWORD dwLen = pStream->ReadDWORD();
m_arRecords.RemoveAll();
for (DWORD i = 0; i < dwLen; ++i)
{
m_arRecords.Add();
m_arRecords[i].Read(pStream);
}
int pos2 = pStream->GetPosition();
int posE = pos1 + (int)dwSize;
if (pos2 < posE)
{
pStream->Skip(posE - pos2);
}
else
{
int mod = (pos2 - pos1) % 4;
if (0 != mod)
pStream->Skip(4 - mod);
}
}
static void WriteRec(CStream& oStream, DWORD dwType, DWORD dwCommand)
{
oStream.WriteDWORD(dwType);
oStream.WriteDWORD(12);
oStream.WriteDWORD(dwCommand);
}
static void WriteRec(CStream& oStream, DWORD dwType, CStringA strCommand)
{
oStream.WriteDWORD(dwType);
oStream.WriteDWORD((DWORD)strCommand.GetLength() + 8);
oStream.WriteCStringA(strCommand);
}
AVSINLINE int GetCoverOffset()
{
size_t nCount = m_arRecords.GetCount();
for (size_t i = 0; i < nCount; ++i)
{
if (CEXTHRecord::exthCoverOffset == m_arRecords[i].m_eType)
{
return (int)m_arRecords[i].m_dwValue;
}
}
return -1;
}
};
class CMobiHeader
{
public:
USHORT Compression;
DWORD TextLength;
USHORT RecordCount;
USHORT RecordSize;
DWORD CurrentPosition;
USHORT EncryptionType;
CString Type;
DWORD HeaderLength;
DWORD MobiType;
DWORD TextEncoding;
DWORD UID;
DWORD Version;
DWORD OrtographicIndex;
DWORD InflectionIndex;
DWORD IndexNames;
DWORD IndexKeys;
DWORD ExtraIndex0;
DWORD ExtraIndex1;
DWORD ExtraIndex2;
DWORD ExtraIndex3;
DWORD ExtraIndex4;
DWORD ExtraIndex5;
DWORD FirstNonBookIndex;
DWORD FullNameOffset;
DWORD FullNameLength;
DWORD Locale;
DWORD InputLanguage;
DWORD OutputLanguage;
DWORD MinVersion;
DWORD FirstImageIndex;
DWORD HuffmanRecordOffset;
DWORD HuffmanRecordCount;
DWORD HuffmanTableOffset;
DWORD HuffmanTableLength;
DWORD ExthFlags;
bool IsDRM;
DWORD DRMOffset;
DWORD DRMCount;
DWORD DRMSize;
DWORD DRMFlags;
bool IsExtra;
DWORD FirstContentRecord;
DWORD LastContentRecord;
DWORD FCIS_Number;
DWORD FCIS_Count;
DWORD FLIS_Number;
DWORD FLIS_Count;
DWORD SrcsRecordIndex;
DWORD NumSrcsRecords;
DWORD ExtraDataFlags;
bool IsMultibytes;
bool IsIndexingBytes;
bool IsUncrossableBreaks;
DWORD PrimaryIndexRecord;
CEXTHHeader m_oEXTH;
public:
CMobiHeader()
{
Compression = 0;
TextLength = 0;
RecordCount = 0;
RecordSize = 0;
CurrentPosition = 0;
EncryptionType = 0;
Type = _T("");
HeaderLength = 0;
MobiType = 0;
TextEncoding = 0;
UID = 0;
Version = 0;
OrtographicIndex = 0;
InflectionIndex = 0;
IndexNames = 0;
IndexKeys = 0;
ExtraIndex0 = 0;
ExtraIndex1 = 0;
ExtraIndex2 = 0;
ExtraIndex3 = 0;
ExtraIndex4 = 0;
ExtraIndex5 = 0;
FirstNonBookIndex = 0;
FullNameOffset = 0;
FullNameLength = 0;
Locale = 0;
InputLanguage = 0;
OutputLanguage = 0;
MinVersion = 0;
FirstImageIndex = 0;
HuffmanRecordOffset = 0;
HuffmanRecordCount = 0;
HuffmanTableOffset = 0;
HuffmanTableLength = 0;
ExthFlags = 0;
IsDRM = false;
DRMOffset = 0;
DRMCount = 0;
DRMSize = 0;
DRMFlags = 0;
IsExtra = false;
FirstContentRecord = 0;
LastContentRecord = 0;
FCIS_Number = 0;
FCIS_Count = 0;
FLIS_Number = 0;
FLIS_Count = 0;
SrcsRecordIndex = 0;
NumSrcsRecords = 0;
ExtraDataFlags = 0;
IsMultibytes = false;
IsIndexingBytes = false;
IsUncrossableBreaks = false;
PrimaryIndexRecord = 0;
}
~CMobiHeader()
{
}
void Read(CStream* pStream, CSection* pRecord, bool bIsMobi = true)
{
pStream->Seek(pRecord->m_oHeader.Offset);
Compression = pStream->ReadUShort();
pStream->Skip(2);
TextLength = pStream->ReadDWORD();
RecordCount = pStream->ReadUShort();
RecordSize = pStream->ReadUShort();
CurrentPosition = 0;//pStream->ReadDWORD();
if (!bIsMobi)
return;
EncryptionType = pStream->ReadUShort();
pStream->Skip(2);
Type = pStream->ReadStringA(4);
HeaderLength = pStream->ReadDWORD();
MobiType = pStream->ReadDWORD();
TextEncoding = pStream->ReadDWORD();
UID = pStream->ReadDWORD();
Version = pStream->ReadDWORD();
OrtographicIndex = pStream->ReadDWORD();
InflectionIndex = pStream->ReadDWORD();
IndexNames = pStream->ReadDWORD();
IndexKeys = pStream->ReadDWORD();
ExtraIndex0 = pStream->ReadDWORD();
ExtraIndex1 = pStream->ReadDWORD();
ExtraIndex2 = pStream->ReadDWORD();
ExtraIndex3 = pStream->ReadDWORD();
ExtraIndex4 = pStream->ReadDWORD();
ExtraIndex5 = pStream->ReadDWORD();
FirstNonBookIndex = pStream->ReadDWORD();
FullNameOffset = pStream->ReadDWORD();
FullNameLength = pStream->ReadDWORD();
Locale = pStream->ReadDWORD();
InputLanguage = pStream->ReadDWORD();
OutputLanguage = pStream->ReadDWORD();
MinVersion = pStream->ReadDWORD();
FirstImageIndex = pStream->ReadDWORD();
HuffmanRecordOffset = pStream->ReadDWORD();
HuffmanRecordCount = pStream->ReadDWORD();
HuffmanTableOffset = pStream->ReadDWORD();
HuffmanTableLength = pStream->ReadDWORD();
ExthFlags = pStream->ReadDWORD();
IsDRM = (HeaderLength > 174) ? true : false;
if (IsDRM)
{
pStream->Skip(32);
DRMOffset = pStream->ReadDWORD();
DRMCount = pStream->ReadDWORD();
DRMSize = pStream->ReadDWORD();
DRMFlags = pStream->ReadDWORD();
}
IsExtra = (HeaderLength >= 232) ? true : false;
if (IsExtra)
{
pStream->Skip(12);
FirstContentRecord = pStream->ReadUShort();
LastContentRecord = pStream->ReadUShort();
pStream->Skip(4);
FCIS_Number = pStream->ReadDWORD();
FCIS_Count = pStream->ReadDWORD();
FLIS_Number = pStream->ReadDWORD();
FLIS_Count = pStream->ReadDWORD();
pStream->Skip(8);
SrcsRecordIndex = pStream->ReadDWORD();
NumSrcsRecords = pStream->ReadDWORD();
pStream->Skip(8);
ExtraDataFlags = pStream->ReadDWORD();
IsMultibytes = ((ExtraDataFlags & 0xb1) != 0x00);
IsIndexingBytes = ((ExtraDataFlags & 0x10) != 0x00);
IsUncrossableBreaks = ((ExtraDataFlags & 0xb100) != 0x00);
PrimaryIndexRecord = pStream->ReadDWORD();
}
if ((ExthFlags & 0x40) != 0x00)
{
pStream->Seek(pRecord->m_oHeader.Offset + 16 + HeaderLength);
m_oEXTH.Read(pStream);
}
}
};
public:
NSEBook::CTempManager m_oTempManager;
bool m_bIsCorrectHtml;
CString m_strMeta;
public:
CMobiReader()
{
m_oTempManager.m_strTempDirectory = _T("C:\\PPTMemory\\MOBI");
m_oTempManager.m_strTempImagesDirectory = m_oTempManager.m_strTempDirectory + _T("\\media");
m_bIsCorrectHtml = false;
}
bool OpenFile(CString strFileName, bool& bIsDRM)
{
m_oTempManager.InitTempDirectory();
CFile oFile;
oFile.OpenFile(strFileName);
CStream oStream;
oStream.FromFile(&oFile);
CPDBHeader oPDBHeader;
oPDBHeader.ReadFromStream(&oStream);
int nCountRecords = (int)oPDBHeader.NumberOfRecords;
CSection* pSections = new CSection[nCountRecords];
for (int i = 0; i < nCountRecords; ++i)
pSections[i].m_oHeader.Read(&oStream);
for (int i = 0; i < nCountRecords; ++i)
{
if (i == (nCountRecords - 1))
pSections[i].Length = oStream.GetSize() - pSections[i].m_oHeader.Offset;
else
pSections[i].Length = pSections[i + 1].m_oHeader.Offset - pSections[i].m_oHeader.Offset;
}
m_strMeta = _T("<meta>");
bool bIsMobi = (_T("BOOKMOBI") == oPDBHeader.Type) ? TRUE : FALSE;
CMobiHeader oHeader;
oHeader.Read(&oStream, &pSections[0], _T("BOOKMOBI") == oPDBHeader.Type);
/*
if (oHeader.IsDRM)
{
// . -
bIsDRM = true;
oFile.CloseFile();
RELEASEARRAYOBJECTS(pSections);
return false;
}
*/
CAtlArray<NSMobi::CMobiReader::CEXTHRecord>* pArrayRecs = &oHeader.m_oEXTH.m_arRecords;
size_t nCountRecsCount = pArrayRecs->GetCount();
for (size_t i = 0; i < nCountRecsCount; ++i)
{
if (CEXTHRecord::exthAuthor == pArrayRecs->GetAt(i).m_eType)
{
m_strMeta += (_T("<author>") + CorrectString2(pArrayRecs->GetAt(i).m_strValue) + _T("</author>"));
}
else if (CEXTHRecord::exthDescription == pArrayRecs->GetAt(i).m_eType)
{
m_strMeta += (_T("<annotation>") + CorrectString2(pArrayRecs->GetAt(i).m_strValue) + _T("</annotation>"));
}
else if (CEXTHRecord::exthPublisher == pArrayRecs->GetAt(i).m_eType)
{
m_strMeta += (_T("<publisher>") + CorrectString2(pArrayRecs->GetAt(i).m_strValue) + _T("</publisher>"));
}
}
LONG lPos2 = pSections[1].m_oHeader.Offset;
LONG lPos1 = oStream.GetPosition();
if (lPos2 > lPos1)
{
m_strMeta += (_T("<name>") + CorrectString2(oStream.ReadStringUTF8(lPos2 - lPos1)) + _T("</name>"));
}
int nCoverOffset = oHeader.m_oEXTH.GetCoverOffset();
if (-1 != nCoverOffset)
m_strMeta += _T("<coverpage>1</coverpage>");
m_strMeta += _T("</meta>");
int nNumberOfTextRecords = oHeader.RecordCount;
int nFirstNonBook = oHeader.FirstNonBookIndex;
int nFirstImage = oHeader.FirstImageIndex;
if (!bIsMobi)
{
nFirstImage = nCountRecords;
}
CHuffmanReader oHuffmanDecoder;
if ((1 != oHeader.Compression) && (2 != oHeader.Compression))
{
int nHuffOffset = (int)oHeader.HuffmanRecordOffset;
int nCountHuff = (int)oHeader.HuffmanRecordCount;
oHuffmanDecoder.LoadTables(&oStream, pSections + nHuffOffset, nCountHuff);
}
int nStart = 1;
int nEnd = min(nCountRecords, nNumberOfTextRecords + 1);
CBufferedText oBuffText;
for (int nIndexTextRec = nStart; nIndexTextRec < nEnd; ++nIndexTextRec)
{
oStream.Seek((int)pSections[nIndexTextRec].m_oHeader.Offset);
if (2 == oHeader.Compression)
{
BYTE* pUncompress = NULL;
LONG lUncompressLen = 0;
int _nStart = 0;
int _nEnd = (int)pSections[nIndexTextRec].Length - 1;
CTextDecoder::GetTralingData(oStream.GetCurrentData(), oHeader.ExtraDataFlags, _nStart, _nEnd);
CTextDecoder::PalmDecode(oStream.GetCurrentData() + _nStart, _nEnd - _nStart + 1, pUncompress, lUncompressLen);
oBuffText.WriteData(pUncompress, min(4096, lUncompressLen));
//CString strMem = CFile::GetCStringFromUTF8(pUncompress, min(4096, lUncompressLen));
RELEASEARRAYOBJECTS(pUncompress);
}
else if (1 == oHeader.Compression)
{
oBuffText.WriteData(oStream.GetCurrentData(), pSections[nIndexTextRec].Length);
}
else
{
BYTE* pUncompress = NULL;
LONG lUncompressLen = 0;
int _nStart = 0;
int _nEnd = (int)pSections[nIndexTextRec].Length - 1;
CTextDecoder::GetTralingData(oStream.GetCurrentData(), oHeader.ExtraDataFlags, _nStart, _nEnd);
oHuffmanDecoder.Decode(oStream.GetCurrentData() + _nStart, _nEnd - _nStart + 1, pUncompress, lUncompressLen);
oBuffText.WriteData(pUncompress, min(4096, lUncompressLen));
//CString strMem = CFile::GetCStringFromUTF8(pUncompress, min(4096, lUncompressLen));
RELEASEARRAYOBJECTS(pUncompress);
}
}
CString strAllText = _T("");
if (!bIsMobi)
{
strAllText = CString((char*)oBuffText.GetData(), (int)oBuffText.GetCurSize());
}
else
{
strAllText = CFile::GetCStringFromUTF8(oBuffText.GetData(), (LONG)oBuffText.GetCurSize());
}
if (_T("") == strAllText)
{
//
bIsDRM = true;
oFile.CloseFile();
RELEASEARRAYOBJECTS(pSections);
return false;
}
CFile oFileHtml;
oFileHtml.CreateFile(m_oTempManager.m_strTempDirectory + _T("\\index.html"));
int nIndexSavedImage = 1;
for (int nIndexImageRecord = nFirstImage; nIndexImageRecord < nCountRecords; ++nIndexImageRecord)
{
oStream.Seek((int)pSections[nIndexImageRecord].m_oHeader.Offset);
CString strType = oStream.ReadStringA(4);
if ((_T("FLIS") == strType) || (_T("FCIS") == strType) || (_T("SRCS") == strType))
{
continue;
}
oStream.Skip(-4);
CFile oFileImage;
CString strNumImage = _T("");
strNumImage.Format(_T("%d.jpg"), nIndexSavedImage++);
oFileImage.CreateFile(m_oTempManager.m_strTempImagesDirectory + _T("\\image") + strNumImage);
oFileImage.WriteFile((void*)oStream.GetCurrentData(), pSections[nIndexImageRecord].Length);
oFileImage.CloseFile();
}
if (m_bIsCorrectHtml && bIsMobi)
{
int nLen = min(200, strAllText.GetLength());
CString strStart = strAllText.Mid(0, nLen);
strStart.MakeLower();
if (-1 == strStart.Find(_T("utf-8")))
{
strAllText.Replace(_T("<head>"), _T("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></meta>"));
}
if (-1 != nCoverOffset)
{
int nBody1 = strAllText.Find(_T("<body"));
int nBody2 = strAllText.Find(_T("<BODY"));
int nBody = max(nBody1, nBody2);
if (-1 != nBody)
{
int n__ = strAllText.Find(TCHAR('>'), nBody);
++n__;
if (0 != n__)
{
CString str = _T("");
str.Format(_T("%d"), nCoverOffset + 1);
strAllText.Insert(n__, _T("<div style=\"text-align:center;\"><img style=\"center;width:100%;height:100%;\" src=\"media/image") + str + _T(".jpg\"/></div>"));
}
}
}
// , recindex!
for (int indexImage = 1; indexImage < nIndexSavedImage; ++indexImage)
{
CString strNum = _T("");
strNum.Format(_T("%d"), indexImage);
int nLenNum = strNum.GetLength();
for (int i = nLenNum; i <= 5; ++i)
{
CString strOld = _T("recindex=\"") + strNum + _T("\"");
CString strNew = _T("");
strNew.Format(_T("src=\"media/image%d.jpg\""), indexImage);
strAllText.Replace(strOld, strNew);
strNum = _T("0") + strNum;
}
}
strAllText.Replace(_T("<mbp:pagebreak/>"), _T("<p style=\"page-break-after:always\"/>"));
strAllText.Replace(_T("<mbp:pagebreak>"), _T("<p style=\"page-break-after:always\"/>"));
}
if (!bIsMobi)
{
BYTE utf8_mem[3];
utf8_mem[0] = 0xEF;
utf8_mem[1] = 0xBB;
utf8_mem[2] = 0xBF;
oFileHtml.WriteFile((void*)utf8_mem, 3);
}
oFileHtml.WriteStringUTF8(strAllText);
oFileHtml.CloseFile();
oFile.CloseFile();
RELEASEARRAYOBJECTS(pSections);
return bIsMobi;
}
void CloseFile()
{
m_oTempManager.RemoveTempDirectory();
}
};
}
\ No newline at end of file
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();
//
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;
}
};
}
\ No newline at end of file
#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);
}
}
}
};
}
\ No newline at end of file
#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("");
}
};
}
\ No newline at end of file
#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))
{
//
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)
{
// ,
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))
{
//
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)
{
// ,
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);
// 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);
}
};
}
\ No newline at end of file
#pragma once
#include "Writer.h"
namespace NSEBook
{
class CWriter_Docx
{
public:
void CreateDocument(CWriter* pWriter)
{
}
void CloseFile(CString strDstFile, CWriter* pWriter)
{
}
};
}
\ No newline at end of file
#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 );//
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 -
return 0;
}
int CompressEpubDir( CString sSource, CString sDestination )
{
int err = 0;
zipFile zf = zipOpen( sDestination, APPEND_STATUS_CREATE );
if( NULL == zf )
return 1;
// mimetype
CString sMimeFile = sSource + _T("\\mimetype");
if( ::GetFileAttributes( sMimeFile ) != INVALID_FILE_ATTRIBUTES )
err = _WriteFileToZip( sMimeFile, _T("mimetype"), zf, Z_NO_COMPRESSION );
if( err == 0 )
{
//
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\"/>"));
// 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))
{
// !
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();
}
};
}
\ No newline at end of file
#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))
{
// !
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)
{
}
};
}
\ No newline at end of file
#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)
{
// 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);
}
// ---------------------------------------------------
//
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)
{
//
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)
{
//
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))
{
// !
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)
{
}
};
}
\ No newline at end of file
//{{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
// 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"
\ No newline at end of file
// 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")
\ No newline at end of file
#pragma once
//1
//0
//0
//19
#define INTVER 1,0,0,19
#define STRVER "1,0,0,19\0"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment