HGGitLab

Commit 4795996f authored by luoliangyi's avatar luoliangyi

1)集成OFD读取和写入功能

2)HGUtility.h中增加实用的几个函数
parent 74c59cf6
......@@ -29,7 +29,7 @@ struct HGDllImpl
HGResult HGAPI HGBase_CreateDll(const HGChar* fileName, HGDll* dll)
{
if (NULL == fileName || '\0' == *fileName || NULL == dll)
if (NULL == fileName || NULL == dll)
{
return HGBASE_ERR_INVALIDARG;
}
......
#include "HGUtility.h"
\ No newline at end of file
#include "HGUtility.h"
#if !defined(HG_CMP_MSC)
#include <uuid/uuid.h>
#else
#include <Shlobj.h>
#include <objbase.h>
#endif
HGResult HGAPI HGBase_GetTmpPath(HGChar* path, HGUInt maxLen)
{
if (NULL == path || 0 == maxLen)
{
return HGBASE_ERR_INVALIDARG;
}
#if !defined(HG_CMP_MSC)
if (maxLen < strlen("/tmp/") + 1)
return HGBASE_ERR_FAIL;
strcpy(path, "/tmp/");
#else
CHAR tmpPath[MAX_PATH] = { 0 };
GetTempPathA(MAX_PATH, tmpPath);
if (maxLen < strlen(tmpPath) + 1)
return HGBASE_ERR_FAIL;
strcpy(path, tmpPath);
#endif
return HGBASE_ERR_OK;
}
HGResult HGAPI HGBase_GetCurrentDir(HGChar* dir, HGUInt maxLen)
{
if (NULL == dir || 0 == maxLen)
{
return HGBASE_ERR_INVALIDARG;
}
#if !defined(HG_CMP_MSC)
char buffer[512] = { 0 };
char* p = getcwd(buffer, 512);
if (NULL == p || maxLen < strlen(buffer) + 1)
return HGBASE_ERR_FAIL;
strcpy(dir, buffer);
#else
CHAR buffer[MAX_PATH] = { 0 };
GetCurrentDirectoryA(MAX_PATH, buffer);
if (maxLen < strlen(buffer) + 1)
return HGBASE_ERR_FAIL;
strcpy(dir, buffer);
#endif
return HGBASE_ERR_OK;
}
HGResult HGAPI HGBase_SetCurrentDir(const HGChar* dir)
{
if (NULL == dir)
{
return HGBASE_ERR_INVALIDARG;
}
#if !defined(HG_CMP_MSC)
if (0 != chdir(dir))
return HGBASE_ERR_FAIL;
#else
if (!SetCurrentDirectoryA(dir))
return HGBASE_ERR_FAIL;
#endif
return HGBASE_ERR_OK;
}
HGResult HGAPI HGBase_CreateDir(const HGChar* dir)
{
if (NULL == dir)
{
return HGBASE_ERR_INVALIDARG;
}
#if !defined(HG_CMP_MSC)
bool ret = true;
char muldir[512] = { 0 };
strcpy(muldir, dir);
for (size_t i = 0; i < strlen(muldir); ++i)
{
if ('/' == muldir[i])
{
muldir[i] = '\0';
if ('\0' != *muldir && 0 != access(muldir, 0))
{
if (0 != mkdir(muldir, 0777))
{
ret = false;
break;
}
}
muldir[i] = '/';
}
}
if (ret)
{
if ('\0' != *muldir && 0 != access(muldir, 0))
{
if (0 != mkdir(muldir, 0777))
{
ret = false;
}
}
}
if (!ret)
return HGBASE_ERR_FAIL;
#else
if (ERROR_SUCCESS != SHCreateDirectoryExA(NULL, dir, NULL))
return HGBASE_ERR_FAIL;
#endif
return HGBASE_ERR_OK;
}
HGResult HGAPI HGBase_DeleteDir(const HGChar* dir)
{
if (NULL == dir)
{
return HGBASE_ERR_INVALIDARG;
}
#if !defined(HG_CMP_MSC)
if (0 != rmdir(dir))
return HGBASE_ERR_FAIL;
#else
if (!RemoveDirectoryA(dir))
return HGBASE_ERR_FAIL;
#endif
return HGBASE_ERR_OK;
}
HGResult HGAPI HGBase_DeleteFile(const HGChar* fileName)
{
if (NULL == fileName)
{
return HGBASE_ERR_INVALIDARG;
}
#if !defined(HG_CMP_MSC)
if (0 != unlink(fileName))
return HGBASE_ERR_FAIL;
#else
if (!DeleteFileA(fileName))
return HGBASE_ERR_FAIL;
#endif
return HGBASE_ERR_OK;
}
HGResult HGAPI HGBase_GetModuleName(HGPointer addr, HGChar* name, HGUInt maxLen)
{
if (NULL == addr || NULL == name || 0 == maxLen)
{
return HGBASE_ERR_INVALIDARG;
}
#if !defined(HG_CMP_MSC)
Dl_info dlinfo;
if (0 == dladdr(addr, &dlinfo))
return HGBASE_ERR_FAIL;
if (maxLen < strlen(dlinfo.dli_fname) + 1)
return HGBASE_ERR_FAIL;
strcpy(name, dlinfo.dli_fname);
#else
HMODULE hModule = NULL;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
| GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)addr, &hModule);
if (NULL == hModule)
return HGBASE_ERR_FAIL;
CHAR moduleName[MAX_PATH] = { 0 };
GetModuleFileNameA(hModule, moduleName, MAX_PATH);
if (maxLen < strlen(moduleName) + 1)
return HGBASE_ERR_FAIL;
strcpy(name, moduleName);
#endif
return HGBASE_ERR_OK;
}
HGResult HGAPI HGBase_GetUuid(HGChar* uuid, HGUInt maxLen)
{
if (NULL == uuid || 0 == maxLen)
{
return HGBASE_ERR_INVALIDARG;
}
#if !defined(HG_CMP_MSC)
uuid_t uuid;
uuid_generate(uuid);
char str[128];
uuid_unparse(uuid, str);
if (maxLen < strlen(str) + 1)
return HGBASE_ERR_FAIL;
strcpy(uuid, str);
#else
GUID guid;
if (S_OK != CoCreateGuid(&guid))
return HGBASE_ERR_FAIL;
char str[128];
sprintf(str, "%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]);
if (maxLen < strlen(str) + 1)
return HGBASE_ERR_FAIL;
strcpy(uuid, str);
#endif
return HGBASE_ERR_OK;
}
HGResult HGAPI HGBase_GetTmpFileName(HGChar* fileName, HGUInt maxLen)
{
if (NULL == fileName || 0 == maxLen)
{
return HGBASE_ERR_INVALIDARG;
}
HGChar path[256] = { 0 }, uuid[128] = {0};
HGBase_GetTmpPath(path, 256);
HGBase_GetUuid(uuid, 128);
strcat(path, uuid);
if (maxLen < strlen(path) + 1)
return HGBASE_ERR_FAIL;
strcpy(fileName, path);
return HGBASE_ERR_OK;
}
\ No newline at end of file
......@@ -4,4 +4,42 @@
#include "HGDef.h"
#include "HGBaseErr.h"
/* 获取系统临时文件目录
*/
HGEXTERN_C HGResult HGAPI HGBase_GetTmpPath(HGChar* path, HGUInt maxLen);
/* 获取进程的当前工作目录
*/
HGEXTERN_C HGResult HGAPI HGBase_GetCurrentDir(HGChar* dir, HGUInt maxLen);
/* 设置进程的当前工作目录
*/
HGEXTERN_C HGResult HGAPI HGBase_SetCurrentDir(const HGChar* dir);
/* 创建目录
* 该函数可以创建多级目录
*/
HGEXTERN_C HGResult HGAPI HGBase_CreateDir(const HGChar* dir);
/* 删除目录
* 该函数只能用于删除空目录
*/
HGEXTERN_C HGResult HGAPI HGBase_DeleteDir(const HGChar* dir);
/* 删除文件
*/
HGEXTERN_C HGResult HGAPI HGBase_DeleteFile(const HGChar* fileName);
/* 获取模块名称
*/
HGEXTERN_C HGResult HGAPI HGBase_GetModuleName(HGPointer addr, HGChar* name, HGUInt maxLen);
/* 获取UUID
*/
HGEXTERN_C HGResult HGAPI HGBase_GetUuid(HGChar* uuid, HGUInt maxLen);
/* 获取临时文件名
*/
HGEXTERN_C HGResult HGAPI HGBase_GetTmpFileName(HGChar* fileName, HGUInt maxLen);
#endif /* __HGUTILITY_H__ */
\ No newline at end of file
......@@ -33,6 +33,16 @@ HGBase_DestroyLog
HGBase_GetLogFileSize
HGBase_WriteLog
HGBase_GetTmpPath
HGBase_GetCurrentDir
HGBase_SetCurrentDir
HGBase_CreateDir
HGBase_DeleteDir
HGBase_DeleteFile
HGBase_GetModuleName
HGBase_GetUuid
HGBase_GetTmpFileName
HGBase_CreateBuffer
HGBase_CreateBufferFromData
HGBase_CreateBufferWithData
......
......@@ -6,7 +6,7 @@ extern "C"
HGResult HGAPI HGImgFmt_CheckBmpFile(const HGChar* fileName, HGBool* isBmp)
{
if (NULL == fileName || '\0' == *fileName || NULL == isBmp)
if (NULL == fileName || NULL == isBmp)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -49,7 +49,7 @@ static void bitmap_destroy(void* bitmap)
HGResult HGAPI HGImgFmt_LoadBmpImage(const HGChar* fileName, HGBmpLoadInfo* info,
HGUInt imgType, HGUInt imgOrigin, HGImage* image)
{
if (NULL == fileName || '\0' == *fileName)
if (NULL == fileName)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -248,7 +248,7 @@ HGResult HGAPI HGImgFmt_LoadBmpImage(const HGChar* fileName, HGBmpLoadInfo* info
HGResult HGAPI HGImgFmt_SaveBmpImage(HGImage image, const HGBmpSaveInfo* info, const HGChar* fileName)
{
if (NULL == image || NULL == fileName || '\0' == *fileName)
if (NULL == image || NULL == fileName)
{
return HGBASE_ERR_INVALIDARG;
}
......
......@@ -37,7 +37,7 @@ struct HGImgFmtWriterImpl
HGResult HGAPI HGImgFmt_GetImgFmtType(const HGChar* fileName, HGUInt* fmtType)
{
if (NULL == fileName || '\0' == *fileName || NULL == fmtType)
if (NULL == fileName || NULL == fmtType)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -95,7 +95,7 @@ HGResult HGAPI HGImgFmt_GetImgFmtType(const HGChar* fileName, HGUInt* fmtType)
HGResult HGAPI HGImgFmt_GetImgFmtTypeFromFileName(const HGChar* fileName, HGUInt* fmtType)
{
if (NULL == fileName || '\0' == *fileName || NULL == fmtType)
if (NULL == fileName || NULL == fmtType)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -200,7 +200,7 @@ HGEXTERN_C HGResult HGAPI HGImgFmt_IsMultiImgFmtType(HGUInt fmtType, HGBool* isM
HGResult HGAPI HGImgFmt_LoadImage(const HGChar* fileName, HGUInt fmtType, HGImgFmtLoadInfo* info,
HGUInt imgType, HGUInt imgOrigin, HGImage* image)
{
if (NULL == fileName || '\0' == *fileName)
if (NULL == fileName)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -512,7 +512,7 @@ HGResult HGAPI HGImgFmt_LoadImage(const HGChar* fileName, HGUInt fmtType, HGImgF
HGResult HGAPI HGImgFmt_SaveImage(HGImage image, HGUInt fmtType, const HGImgFmtSaveInfo* info, const HGChar* fileName)
{
if (NULL == image || fmtType > HGIMGFMT_TYPE_OFD || NULL == fileName || '\0' == *fileName)
if (NULL == image || fmtType > HGIMGFMT_TYPE_OFD || NULL == fileName)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -654,7 +654,7 @@ HGResult HGAPI HGImgFmt_SaveImage(HGImage image, HGUInt fmtType, const HGImgFmtS
HGResult HGAPI HGImgFmt_OpenImageReader(const HGChar* fileName, HGUInt fmtType, HGImgFmtReader* reader)
{
if (NULL == fileName || '\0' == *fileName || fmtType > HGIMGFMT_TYPE_OFD || NULL == reader)
if (NULL == fileName || fmtType > HGIMGFMT_TYPE_OFD || NULL == reader)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -994,7 +994,7 @@ HGResult HGAPI HGImgFmt_LoadImageFromReader(HGImgFmtReader reader, HGUInt index,
HGResult HGAPI HGImgFmt_OpenImageWriter(const HGChar* fileName, HGUInt fmtType, HGImgFmtWriter* writer)
{
if (NULL == fileName || '\0' == *fileName || fmtType > HGIMGFMT_TYPE_OFD || NULL == writer)
if (NULL == fileName || fmtType > HGIMGFMT_TYPE_OFD || NULL == writer)
{
return HGBASE_ERR_INVALIDARG;
}
......
......@@ -20,7 +20,7 @@ METHODDEF(void) my_error_exit(j_common_ptr cinfo)
HGResult HGAPI HGImgFmt_CheckJpegFile(const HGChar* fileName, HGBool* isJpeg)
{
if (NULL == fileName || '\0' == *fileName || NULL == isJpeg)
if (NULL == fileName || NULL == isJpeg)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -34,7 +34,7 @@ HGResult HGAPI HGImgFmt_CheckJpegFile(const HGChar* fileName, HGBool* isJpeg)
HGResult HGAPI HGImgFmt_LoadJpegImage(const HGChar* fileName, HGJpegLoadInfo* info,
HGUInt imgType, HGUInt imgOrigin, HGImage* image)
{
if (NULL == fileName || '\0' == *fileName)
if (NULL == fileName)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -270,7 +270,7 @@ HGResult HGAPI HGImgFmt_LoadJpegImageFromBuffer(HGBuffer buffer, HGJpegLoadInfo*
HGResult HGAPI HGImgFmt_SaveJpegImage(HGImage image, const HGJpegSaveInfo* info, const HGChar* fileName)
{
if (NULL == image || NULL == fileName || '\0' == *fileName)
if (NULL == image || NULL == fileName)
{
return HGBASE_ERR_INVALIDARG;
}
......
......@@ -3,7 +3,7 @@
HGResult HGAPI HGImgFmt_CheckOfdFile(const HGChar* fileName, HGBool* isOfd)
{
if (NULL == fileName || '\0' == *fileName || NULL == isOfd)
if (NULL == fileName || NULL == isOfd)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -21,7 +21,7 @@ HGResult HGAPI HGImgFmt_CheckOfdFile(const HGChar* fileName, HGBool* isOfd)
HGResult HGAPI HGImgFmt_OpenOfdReader(const HGChar* fileName, HGOfdReader* reader)
{
if (NULL == fileName || '\0' == *fileName || NULL == reader)
if (NULL == fileName || NULL == reader)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -92,7 +92,7 @@ HGResult HGAPI HGImgFmt_LoadImageFromOfdReader(HGOfdReader reader, HGUInt page,
HGResult HGAPI HGImgFmt_OpenOfdImageWriter(const HGChar* fileName, HGOfdImageWriter* writer)
{
if (NULL == fileName || '\0' == *fileName || NULL == writer)
if (NULL == fileName || NULL == writer)
{
return HGBASE_ERR_INVALIDARG;
}
......
#include "HGOfdImpl.hpp"
#include "tinyxml2.h"
#include "../base/HGUtility.h"
#define A4page_page_PhysicalBox "0.000000 0.000000 197.273333 139.022667"
HGOfdReaderImpl::HGOfdReaderImpl()
{
......@@ -25,37 +27,44 @@ HGResult HGOfdReaderImpl::Open(const HGChar* fileName)
return HGBASE_ERR_FAIL;
}
bool findOfdXml = false;
zip_int64_t n_entries = zip_get_num_entries(m_zip, ZIP_FL_UNCHANGED);
for (zip_int64_t i = 0; i < n_entries; i++)
std::string content;
if (!ReadXml("Doc_0/Document.xml", content))
{
const char* name = zip_get_name(m_zip, i, ZIP_FL_ENC_GUESS);
if (0 == _stricmp(name, "OFD.xml"))
{
findOfdXml = true;
}
struct zip_stat st;
zip_stat_init(&st);
zip_stat(m_zip, name, ZIP_FL_NOCASE, &st);
zip_int64_t filesize = st.size;
zip_int64_t compsize = st.comp_size;
std::pair<std::string, zip_int64_t> pr;
pr.first = name;
pr.second = filesize;
m_fileInfo.push_back(pr);
}
if (!findOfdXml)
{
m_fileInfo.clear();
zip_close(m_zip);
m_zip = NULL;
return HGBASE_ERR_FAIL;
}
tinyxml2::XMLDocument xmlDoc;
if (tinyxml2::XML_SUCCESS == xmlDoc.Parse(content.c_str()))
{
tinyxml2::XMLElement* root = xmlDoc.RootElement();
if (NULL != root)
{
tinyxml2::XMLElement* pages = root->FirstChildElement("ofd:Pages");
if (NULL != pages)
{
tinyxml2::XMLElement* page = pages->FirstChildElement("ofd:Page");
if (NULL != page)
{
const char* attr = page->Attribute("BaseLoc");
if (NULL != attr)
m_contentNames.push_back(attr);
tinyxml2::XMLElement* p = page->NextSiblingElement("ofd:Page");
while (NULL != p)
{
const char* attr = p->Attribute("BaseLoc");
if (NULL != attr)
m_contentNames.push_back(attr);
p = p->NextSiblingElement("ofd:Page");
}
}
}
}
}
return HGBASE_ERR_OK;
}
......@@ -66,7 +75,7 @@ HGResult HGOfdReaderImpl::Close()
return HGBASE_ERR_FAIL;
}
m_fileInfo.clear();
m_contentNames.clear();
zip_close(m_zip);
m_zip = NULL;
return HGBASE_ERR_OK;
......@@ -74,27 +83,17 @@ HGResult HGOfdReaderImpl::Close()
HGResult HGOfdReaderImpl::GetPageCount(HGUInt* count)
{
if (NULL == count)
{
return HGBASE_ERR_INVALIDARG;
}
if (NULL == m_zip)
{
return HGBASE_ERR_FAIL;
}
*count = 0;
std::vector<std::pair<std::string, zip_int64_t>>::const_iterator iter;
for (iter = m_fileInfo.begin(); iter != m_fileInfo.end(); ++iter)
if (NULL == count)
{
if (0 == iter->first.find("Doc_0/Pages/Page_")
&& iter->first.size() - strlen("/Content.xml") == iter->first.rfind("/Content.xml"))
{
++(*count);
}
return HGBASE_ERR_INVALIDARG;
}
*count = (HGUInt)m_contentNames.size();
return HGBASE_ERR_OK;
}
......@@ -130,65 +129,31 @@ static bool GetRect(const char *text, double data[4])
HGResult HGOfdReaderImpl::GetPageInfo(HGUInt page, HGOfdPageInfo* info)
{
if (NULL == info)
{
return HGBASE_ERR_INVALIDARG;
}
if (NULL == m_zip)
{
return HGBASE_ERR_FAIL;
}
char name[128];
sprintf(name, "Doc_0/Pages/Page_%u/Content.xml", page);
zip_int64_t size = 0;
std::vector<std::pair<std::string, zip_int64_t>>::const_iterator iter;
for (iter = m_fileInfo.begin(); iter != m_fileInfo.end(); ++iter)
{
if (0 == strcmp(iter->first.c_str(), name))
{
size = iter->second;
break;
}
}
if (0 == size)
{
return HGBASE_ERR_FAIL;
}
zip_file* file = zip_fopen(m_zip, name, ZIP_FL_NOCASE);
if (NULL == file)
if (page >= (HGUInt)m_contentNames.size() || NULL == info)
{
return HGBASE_ERR_FAIL;
return HGBASE_ERR_INVALIDARG;
}
char* content = (char *)malloc((size_t)size + 1);
if (NULL == content)
{
zip_fclose(file);
return HGBASE_ERR_OUTOFMEMORY;
}
char name[128];
sprintf(name, "Doc_0/%s", m_contentNames[page].c_str());
zip_int64_t did_read = zip_fread(file, content, size);
if (did_read != size)
std::string content;
if (!ReadXml(name, content))
{
free(content);
zip_fclose(file);
return HGBASE_ERR_FAIL;
}
content[size] = 0;
HGResult ret = HGBASE_ERR_FAIL;
tinyxml2::XMLDocument xmlDoc;
tinyxml2::XMLError rc = xmlDoc.Parse(content);
if (rc == tinyxml2::XML_SUCCESS)
if (tinyxml2::XML_SUCCESS == xmlDoc.Parse(content.c_str()))
{
tinyxml2::XMLElement* root = xmlDoc.RootElement();
if (root != NULL)
if (NULL != root)
{
tinyxml2::XMLElement* area = root->FirstChildElement("ofd:Area");
if (NULL != area)
......@@ -208,54 +173,208 @@ HGResult HGOfdReaderImpl::GetPageInfo(HGUInt page, HGOfdPageInfo* info)
}
}
free(content);
zip_fclose(file);
return ret;
}
HGResult HGOfdReaderImpl::LoadImage(HGUInt page, HGFloat xScale, HGFloat yScale,
HGUInt imgType, HGUInt imgOrigin, HGImage* image)
{
if (NULL == image)
if (NULL == m_zip)
{
return HGBASE_ERR_FAIL;
}
if (page >= (HGUInt)m_contentNames.size() || NULL == image)
{
return HGBASE_ERR_INVALIDARG;
}
if (NULL == m_zip)
char name[128];
sprintf(name, "Doc_0/%s", m_contentNames[page].c_str());
std::string content;
if (!ReadXml(name, content))
{
return HGBASE_ERR_FAIL;
}
char name[128];
sprintf(name, "Doc_0/Res/image_%u.jpg", page + 1);
tinyxml2::XMLDocument xmlDoc;
zip_int64_t size = 0;
std::vector<std::pair<std::string, zip_int64_t>>::const_iterator iter;
for (iter = m_fileInfo.begin(); iter != m_fileInfo.end(); ++iter)
std::string resId;
if (tinyxml2::XML_SUCCESS == xmlDoc.Parse(content.c_str()))
{
if (0 == strcmp(iter->first.c_str(), name))
tinyxml2::XMLElement* root = xmlDoc.RootElement();
if (NULL != root)
{
size = iter->second;
break;
tinyxml2::XMLElement* content = root->FirstChildElement("ofd:Content");
if (NULL != content)
{
tinyxml2::XMLElement* layer = content->FirstChildElement("ofd:Layer");
if (NULL != layer)
{
const char* attr = layer->Attribute("Type");
if (NULL == attr || 0 != _stricmp("Background", attr))
{
tinyxml2::XMLElement* p = layer->NextSiblingElement("ofd:Layer");
while (NULL != p)
{
const char* attr = p->Attribute("Type");
if (NULL != attr && 0 == _stricmp("Background", attr))
{
break;
}
p = p->NextSiblingElement("ofd:Layer");
}
layer = p;
}
if (NULL != layer)
{
tinyxml2::XMLElement* imgObject = layer->FirstChildElement("ofd:ImageObject");
if (NULL != imgObject)
{
resId = imgObject->Attribute("ResourceID");
}
}
}
}
}
}
if (0 == size)
if (resId.empty())
{
return HGBASE_ERR_FAIL;
}
if (!ReadXml("Doc_0/DocumentRes.xml", content))
{
return HGBASE_ERR_FAIL;
}
std::string imgName;
if (tinyxml2::XML_SUCCESS == xmlDoc.Parse(content.c_str()))
{
tinyxml2::XMLElement* root = xmlDoc.RootElement();
if (NULL != root)
{
tinyxml2::XMLElement* multiMedias = root->FirstChildElement("ofd:MultiMedias");
if (NULL != multiMedias)
{
tinyxml2::XMLElement* multiMedia = multiMedias->FirstChildElement("ofd:MultiMedia");
if (NULL != multiMedia)
{
const char* attr = multiMedia->Attribute("ID");
if (NULL == attr || 0 != _stricmp(resId.c_str(), attr))
{
tinyxml2::XMLElement* p = multiMedia->NextSiblingElement("ofd:MultiMedia");
while (NULL != p)
{
const char* attr = p->Attribute("ID");
if (NULL != attr && 0 == _stricmp(resId.c_str(), attr))
{
break;
}
p = p->NextSiblingElement("ofd:MultiMedia");
}
multiMedia = p;
}
if (NULL != multiMedia)
{
tinyxml2::XMLElement* mediaFile = multiMedia->FirstChildElement("ofd:MediaFile");
if (NULL != mediaFile)
{
imgName = mediaFile->GetText();
}
}
}
}
}
}
if (imgName.empty())
{
return HGBASE_ERR_FAIL;
}
char img_name[128];
sprintf(img_name, "Doc_0/Res/%s", imgName.c_str());
if (!ReadJpeg(img_name, xScale, yScale, imgType, imgOrigin, image))
{
return HGBASE_ERR_FAIL;
}
return HGBASE_ERR_OK;
}
bool HGOfdReaderImpl::ReadXml(const char* name, std::string& content)
{
struct zip_stat st;
zip_stat_init(&st);
zip_stat(m_zip, name, ZIP_FL_NOCASE, &st);
zip_int64_t size = st.size;
if (0 == size)
{
return false;
}
zip_file* file = zip_fopen(m_zip, name, ZIP_FL_NOCASE);
if (NULL == file)
{
return HGBASE_ERR_FAIL;
return false;
}
char* s = (char*)malloc((size_t)size + 1);
if (NULL == s)
{
zip_fclose(file);
return false;
}
zip_int64_t did_read = zip_fread(file, s, size);
if (did_read != size)
{
free(s);
zip_fclose(file);
return false;
}
s[size] = 0;
content = s;
free(s);
zip_fclose(file);
return true;
}
bool HGOfdReaderImpl::ReadJpeg(const char* name, HGFloat xScale, HGFloat yScale, HGUInt imgType, HGUInt imgOrigin, HGImage* image)
{
struct zip_stat st;
zip_stat_init(&st);
zip_stat(m_zip, name, ZIP_FL_NOCASE, &st);
zip_int64_t size = st.size;
if (0 == size)
{
return false;
}
zip_file* file = zip_fopen(m_zip, name, ZIP_FL_NOCASE);
if (NULL == file)
{
return false;
}
unsigned char* content = (unsigned char*)malloc((size_t)size);
if (NULL == content)
{
zip_fclose(file);
return HGBASE_ERR_OUTOFMEMORY;
return false;
}
zip_int64_t did_read = zip_fread(file, content, size);
......@@ -263,7 +382,7 @@ HGResult HGOfdReaderImpl::LoadImage(HGUInt page, HGFloat xScale, HGFloat yScale,
{
free(content);
zip_fclose(file);
return HGBASE_ERR_FAIL;
return false;
}
HGBuffer buffer = NULL;
......@@ -273,13 +392,14 @@ HGResult HGOfdReaderImpl::LoadImage(HGUInt page, HGFloat xScale, HGFloat yScale,
free(content);
zip_fclose(file);
return ret;
return (HGBASE_ERR_OK == ret);
}
HGOfdImageWriterImpl::HGOfdImageWriterImpl()
{
m_zip = NULL;
m_curImgIndex = 0;
}
HGOfdImageWriterImpl::~HGOfdImageWriterImpl()
......@@ -289,15 +409,317 @@ HGOfdImageWriterImpl::~HGOfdImageWriterImpl()
HGResult HGOfdImageWriterImpl::Open(const HGChar* fileName)
{
return HGBASE_ERR_NOTIMPL;
if (NULL != m_zip)
{
return HGBASE_ERR_FAIL;
}
int error = 0;
m_zip = zip_open(fileName, ZIP_CREATE | ZIP_TRUNCATE, &error);
if (NULL == m_zip)
{
return HGBASE_ERR_FAIL;
}
zip_add_dir(m_zip, "Doc_0");
zip_add_dir(m_zip, "Doc_0/Pages");
zip_add_dir(m_zip, "Doc_0/Res");
if (!AddOfdXml() || !AddPublicResXml())
{
zip_close(m_zip);
m_zip = NULL;
return HGBASE_ERR_FAIL;
}
return HGBASE_ERR_OK;
}
HGResult HGOfdImageWriterImpl::Close()
{
return HGBASE_ERR_NOTIMPL;
if (NULL == m_zip)
{
return HGBASE_ERR_FAIL;
}
AddDocXml();
AddDocResXml();
zip_close(m_zip);
m_zip = NULL;
// ʱļ
std::list<std::string>::const_iterator iter;
for (iter = m_tmpFiles.begin(); iter != m_tmpFiles.end(); ++iter)
{
HGBase_DeleteFile(iter->c_str());
}
m_tmpFiles.clear();
return HGBASE_ERR_OK;
}
HGResult HGOfdImageWriterImpl::SaveJpegImage(HGImage image, const HGJpegSaveInfo* info)
{
return HGBASE_ERR_NOTIMPL;
HGChar name[128];
sprintf(name, "Doc_0/Res/image_%u.jpg", m_curImgIndex);
if (!AddJpegImageFile(image, info, name))
{
return HGBASE_ERR_FAIL;
}
AddContentXmlFile(m_curImgIndex);
++m_curImgIndex;
return HGBASE_ERR_OK;
}
bool HGOfdImageWriterImpl::AddOfdXml()
{
tinyxml2::XMLDocument xmlDoc;
HGChar uuid[128];
HGBase_GetUuid(uuid, 128);
time_t tm = time(NULL);
struct tm *local_tm = localtime(&tm);
char local_tm_str[256];
strftime(local_tm_str, 256, "%c", local_tm);
tinyxml2::XMLElement *root = xmlDoc.NewElement("ofd:OFD");
root->SetAttribute("xmlns:ofd", "http://www.ofdspec.org/2016");
root->SetAttribute("DocType", "OFD");
root->SetAttribute("Version", "1.0");
xmlDoc.InsertEndChild(root);
tinyxml2::XMLElement* docBody = xmlDoc.NewElement("ofd:DocBody");
root->InsertEndChild(docBody);
tinyxml2::XMLElement* docRoot = xmlDoc.NewElement("ofd:DocRoot");
docRoot->SetText("Doc_0/Document.xml");
docBody->InsertEndChild(docRoot);
tinyxml2::XMLElement* docInfo = xmlDoc.NewElement("ofd:DocInfo");
docBody->InsertEndChild(docInfo);
tinyxml2::XMLElement* docId = xmlDoc.NewElement("ofd:DocID");
docId->SetText(uuid);
docInfo->InsertEndChild(docId);
tinyxml2::XMLElement* creationDate = xmlDoc.NewElement("ofd:CreationDate");
creationDate->SetText(local_tm_str);
docInfo->InsertEndChild(creationDate);
tinyxml2::XMLElement* modDate = xmlDoc.NewElement("ofd:ModDate");
modDate->SetText(local_tm_str);
docInfo->InsertEndChild(modDate);
tinyxml2::XMLElement* creator = xmlDoc.NewElement("ofd:Creator");
creator->SetText("HuaGo");
docInfo->InsertEndChild(creator);
tinyxml2::XMLElement* createVersion = xmlDoc.NewElement("ofd:CreatorVersion");
createVersion->SetText("1.0.0");
docInfo->InsertEndChild(createVersion);
return AddXmlFile(xmlDoc, "OFD.xml");
}
bool HGOfdImageWriterImpl::AddDocXml()
{
tinyxml2::XMLDocument xmlDoc;
tinyxml2::XMLElement* root = xmlDoc.NewElement("ofd:Document");
root->SetAttribute("xmlns:ofd", "http://www.ofdspec.org/2016");
xmlDoc.InsertEndChild(root);
tinyxml2::XMLElement* commonData = xmlDoc.NewElement("ofd:CommonData");
root->InsertEndChild(commonData);
tinyxml2::XMLElement* maxUnitID = xmlDoc.NewElement("ofd:MaxUnitID");
HGChar maxId[24];
sprintf(maxId, "%u", m_curImgIndex * 10 + 2);
maxUnitID->SetText(maxId);
commonData->InsertEndChild(maxUnitID);
tinyxml2::XMLElement* pageArea = xmlDoc.NewElement("ofd:PageArea");
commonData->InsertEndChild(pageArea);
tinyxml2::XMLElement* publicRes = xmlDoc.NewElement("ofd:PublicRes");
publicRes->SetText("PublicRes.xml");
commonData->InsertEndChild(publicRes);
tinyxml2::XMLElement* documentRes = xmlDoc.NewElement("ofd:DocumentRes");
documentRes->SetText("DocumentRes.xml");
commonData->InsertEndChild(documentRes);
tinyxml2::XMLElement* physicalBox = xmlDoc.NewElement("ofd:PhysicalBox");
physicalBox->SetText(A4page_page_PhysicalBox);
pageArea->InsertEndChild(physicalBox);
tinyxml2::XMLElement* pages = xmlDoc.NewElement("ofd:Pages");
root->InsertEndChild(pages);
for (HGUInt i = 0; i < m_curImgIndex; ++i)
{
tinyxml2::XMLElement* page = xmlDoc.NewElement("ofd:Page");
HGChar id[24];
sprintf(id, "%u", i * 10 + 1);
page->SetAttribute("ID", id);
HGChar loc[128];
sprintf(loc, "Pages/Page_%u/Content.xml", i);
page->SetAttribute("BaseLoc", loc);
pages->InsertEndChild(page);
}
return AddXmlFile(xmlDoc, "Doc_0/Document.xml");
}
bool HGOfdImageWriterImpl::AddDocResXml()
{
tinyxml2::XMLDocument xmlDoc;
tinyxml2::XMLElement* root = xmlDoc.NewElement("ofd:Res");
root->SetAttribute("xmlns:ofd", "http://www.ofdspec.org/2016");
root->SetAttribute("BaseLoc", "Res");
xmlDoc.InsertEndChild(root);
tinyxml2::XMLElement* multiMedias = xmlDoc.NewElement("ofd:MultiMedias");
root->InsertEndChild(multiMedias);
for (HGUInt i = 0; i < m_curImgIndex; ++i)
{
tinyxml2::XMLElement* multiMedia = xmlDoc.NewElement("ofd:MultiMedia");
multiMedia->SetAttribute("Type", "Image");
HGChar id[24];
sprintf(id, "%u", i * 10 + 2);
multiMedia->SetAttribute("ID", id);
multiMedias->InsertEndChild(multiMedia);
tinyxml2::XMLElement* mediaFile = xmlDoc.NewElement("ofd:MediaFile");
HGChar loc[128];
sprintf(loc, "image_%u.jpg", i);
mediaFile->SetText(loc);
multiMedia->InsertEndChild(mediaFile);
}
return AddXmlFile(xmlDoc, "Doc_0/DocumentRes.xml");
}
bool HGOfdImageWriterImpl::AddPublicResXml()
{
tinyxml2::XMLDocument xmlDoc;
tinyxml2::XMLElement* root = xmlDoc.NewElement("ofd:Res");
root->SetAttribute("xmlns:ofd", "http://www.ofdspec.org/2016");
root->SetAttribute("BaseLoc", "Res");
xmlDoc.InsertEndChild(root);
tinyxml2::XMLElement* fonts = xmlDoc.NewElement("ofd:Fonts");
root->InsertEndChild(fonts);
return AddXmlFile(xmlDoc, "Doc_0/PublicRes.xml");
}
bool HGOfdImageWriterImpl::AddXmlFile(tinyxml2::XMLDocument& xmlDoc, const HGChar* name)
{
HGChar tmpName[256];
HGBase_GetTmpFileName(tmpName, 256);
if (tinyxml2::XML_SUCCESS != xmlDoc.SaveFile(tmpName))
{
return false;
}
zip_source_t* s = zip_source_file(m_zip, tmpName, 0, 0);
if (NULL == s)
{
HGBase_DeleteFile(tmpName);
return false;
}
zip_int64_t ret = zip_file_add(m_zip, name, s, ZIP_FL_ENC_UTF_8 | ZIP_FL_OVERWRITE);
if (ret < 0)
{
zip_source_free(s);
HGBase_DeleteFile(tmpName);
return false;
}
m_tmpFiles.push_back(tmpName);
return true;
}
bool HGOfdImageWriterImpl::AddJpegImageFile(HGImage image, const HGJpegSaveInfo* info, const HGChar* name)
{
HGChar tmpName[256];
HGBase_GetTmpFileName(tmpName, 256);
if (HGBASE_ERR_OK != HGImgFmt_SaveJpegImage(image, info, tmpName))
{
return false;
}
zip_source_t* s = zip_source_file(m_zip, tmpName, 0, 0);
if (NULL == s)
{
HGBase_DeleteFile(tmpName);
return false;
}
zip_int64_t ret = zip_file_add(m_zip, name, s, ZIP_FL_OVERWRITE);
if (ret < 0)
{
zip_source_free(s);
HGBase_DeleteFile(tmpName);
return false;
}
m_tmpFiles.push_back(tmpName);
return true;
}
bool HGOfdImageWriterImpl::AddContentXmlFile(HGUInt index)
{
HGChar dir[128];
sprintf(dir, "Doc_0/Pages/Page_%u", index);
zip_add_dir(m_zip, dir);
tinyxml2::XMLDocument xmlDoc;
tinyxml2::XMLElement* root = xmlDoc.NewElement("ofd:Page");
root->SetAttribute("xmlns:ofd", "http://www.ofdspec.org/2016");
xmlDoc.InsertEndChild(root);
tinyxml2::XMLElement* area = xmlDoc.NewElement("ofd:Area");
root->InsertEndChild(area);
tinyxml2::XMLElement* physicalBox = xmlDoc.NewElement("ofd:PhysicalBox");
physicalBox->SetText(A4page_page_PhysicalBox);
area->InsertEndChild(physicalBox);
tinyxml2::XMLElement* content = xmlDoc.NewElement("ofd:Content");
root->InsertEndChild(content);
tinyxml2::XMLElement* layer = xmlDoc.NewElement("ofd:Layer");
HGChar layerId[24];
sprintf(layerId, "%u", index * 10 + 3);
layer->SetAttribute("ID", layerId);
layer->SetAttribute("Type", "Background");
content->InsertEndChild(layer);
tinyxml2::XMLElement* imgObject = xmlDoc.NewElement("ofd:ImageObject");
HGChar imgObjectId[24];
sprintf(imgObjectId, "%u", index * 10 + 4);
imgObject->SetAttribute("ID", imgObjectId);
imgObject->SetAttribute("Boundary", "0.000000 0.000000 197.273333 139.022667");
HGChar imgObjectResId[24];
sprintf(imgObjectResId, "%u", index * 10 + 2);
imgObject->SetAttribute("ResourceID", imgObjectResId);
imgObject->SetAttribute("CTM", "197.273333 0 0 139.022667 0 0");
layer->InsertEndChild(imgObject);
HGChar name[128];
sprintf(name, "%s/Content.xml", dir);
return AddXmlFile(xmlDoc, name);
}
\ No newline at end of file
......@@ -6,7 +6,9 @@ extern "C"
{
#include "zip.h"
};
#include "tinyxml2.h"
#include <vector>
#include <list>
#include <string>
class HGOfdReaderImpl
......@@ -22,9 +24,13 @@ public:
HGResult LoadImage(HGUInt page, HGFloat xScale, HGFloat yScale,
HGUInt imgType, HGUInt imgOrigin, HGImage* image);
private:
bool ReadXml(const char *name, std::string &content);
bool ReadJpeg(const char* name, HGFloat xScale, HGFloat yScale, HGUInt imgType, HGUInt imgOrigin, HGImage* image);
private:
zip* m_zip;
std::vector<std::pair<std::string, zip_int64_t>> m_fileInfo;
std::vector<std::string> m_contentNames;
};
class HGOfdImageWriterImpl
......@@ -36,6 +42,20 @@ public:
HGResult Open(const HGChar* fileName);
HGResult Close();
HGResult SaveJpegImage(HGImage image, const HGJpegSaveInfo* info);
private:
bool AddOfdXml();
bool AddDocXml();
bool AddDocResXml();
bool AddPublicResXml();
bool AddXmlFile(tinyxml2::XMLDocument &xmlDoc, const HGChar *name);
bool AddJpegImageFile(HGImage image, const HGJpegSaveInfo* info, const HGChar* name);
bool AddContentXmlFile(HGUInt index);
private:
zip* m_zip;
std::list<std::string> m_tmpFiles;
HGUInt m_curImgIndex;
};
#endif /* __HGOFDIMPL_HPP__ */
\ No newline at end of file
......@@ -111,7 +111,7 @@ static uint32_t GetUnicodeStrLen(const uint16_t* pUnicode)
HGResult HGAPI HGImgFmt_CheckPdfFile(const HGChar* fileName, HGBool* isPdf)
{
if (NULL == fileName || '\0' == *fileName || NULL == isPdf)
if (NULL == fileName || NULL == isPdf)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -129,7 +129,7 @@ HGResult HGAPI HGImgFmt_CheckPdfFile(const HGChar* fileName, HGBool* isPdf)
HGResult HGAPI HGImgFmt_OpenPdfReader(const HGChar* fileName, HGPdfReader* reader)
{
if (NULL == fileName || '\0' == *fileName || NULL == reader)
if (NULL == fileName || NULL == reader)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -149,6 +149,7 @@ HGResult HGAPI HGImgFmt_OpenPdfReader(const HGChar* fileName, HGPdfReader* reade
HGPdfReaderImpl* pdfReaderImpl = new HGPdfReaderImpl;
pdfReaderImpl->m_pContext = pContext;
pdfReaderImpl->m_pDoc = pDoc;
*reader = (HGPdfReader)pdfReaderImpl;
ret = HGBASE_ERR_OK;
}
fz_catch(pContext)
......@@ -269,7 +270,7 @@ HGResult HGAPI HGImgFmt_LoadImageFromPdfReader(HGPdfReader reader, HGUInt page,
HGResult HGAPI HGImgFmt_OpenPdfImageWriter(const HGChar* fileName, HGPdfImageWriter* writer)
{
if (NULL == fileName || '\0' == *fileName || NULL == writer)
if (NULL == fileName || NULL == writer)
{
return HGBASE_ERR_INVALIDARG;
}
......
......@@ -6,7 +6,7 @@
HGResult HGAPI HGImgFmt_CheckPngFile(const HGChar* fileName, HGBool* isPng)
{
if (NULL == fileName || '\0' == *fileName || NULL == isPng)
if (NULL == fileName || NULL == isPng)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -20,7 +20,7 @@ HGResult HGAPI HGImgFmt_CheckPngFile(const HGChar* fileName, HGBool* isPng)
HGResult HGAPI HGImgFmt_LoadPngImage(const HGChar* fileName, HGPngLoadInfo* info,
HGUInt imgType, HGUInt imgOrigin, HGImage* image)
{
if (NULL == fileName || '\0' == *fileName)
if (NULL == fileName)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -416,7 +416,7 @@ HGResult HGAPI HGImgFmt_LoadPngImage(const HGChar* fileName, HGPngLoadInfo* info
HGResult HGAPI HGImgFmt_SavePngImage(HGImage image, const HGPngSaveInfo* info, const HGChar* fileName)
{
if (NULL == image || NULL == fileName || '\0' == *fileName)
if (NULL == image || NULL == fileName)
{
return HGBASE_ERR_INVALIDARG;
}
......
......@@ -3,7 +3,7 @@
HGResult HGAPI HGImgFmt_CheckTiffFile(const HGChar* fileName, HGBool* isTiff)
{
if (NULL == fileName || '\0' == *fileName || NULL == isTiff)
if (NULL == fileName || NULL == isTiff)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -21,7 +21,7 @@ HGResult HGAPI HGImgFmt_CheckTiffFile(const HGChar* fileName, HGBool* isTiff)
HGResult HGAPI HGImgFmt_OpenTiffReader(const HGChar* fileName, HGTiffReader* reader)
{
if (NULL == fileName || '\0' == *fileName || NULL == reader)
if (NULL == fileName || NULL == reader)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -229,7 +229,7 @@ HGResult HGAPI HGImgFmt_LoadImageFromTiffReader(HGTiffReader reader, HGUInt inde
HGResult HGAPI HGImgFmt_OpenTiffWriter(const HGChar* fileName, HGTiffWriter* writer)
{
if (NULL == fileName || '\0' == *fileName || NULL == writer)
if (NULL == fileName || NULL == writer)
{
return HGBASE_ERR_INVALIDARG;
}
......

// HGImgFmtTest.cpp: 定义应用程序的类行为。
//
#include "pch.h"
#include "framework.h"
#include "HGImgFmtTest.h"
#include "HGImgFmtTestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CHGImgFmtTestApp
BEGIN_MESSAGE_MAP(CHGImgFmtTestApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CHGImgFmtTestApp 构造
CHGImgFmtTestApp::CHGImgFmtTestApp()
{
// 支持重新启动管理器
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
// TODO: 在此处添加构造代码,
// 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的 CHGImgFmtTestApp 对象
CHGImgFmtTestApp theApp;
// CHGImgFmtTestApp 初始化
BOOL CHGImgFmtTestApp::InitInstance()
{
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControlsEx()。 否则,将无法创建窗口。
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// 将它设置为包括所有要在应用程序中使用的
// 公共控件类。
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
// 创建 shell 管理器,以防对话框包含
// 任何 shell 树视图控件或 shell 列表视图控件。
CShellManager *pShellManager = new CShellManager;
// 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
// 标准初始化
// 如果未使用这些功能并希望减小
// 最终可执行文件的大小,则应移除下列
// 不需要的特定初始化例程
// 更改用于存储设置的注册表项
// TODO: 应适当修改该字符串,
// 例如修改为公司或组织名
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
CHGImgFmtTestDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: 在此放置处理何时用
// “确定”来关闭对话框的代码
}
else if (nResponse == IDCANCEL)
{
// TODO: 在此放置处理何时用
// “取消”来关闭对话框的代码
}
else if (nResponse == -1)
{
TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n");
TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
}
// 删除上面创建的 shell 管理器。
if (pShellManager != nullptr)
{
delete pShellManager;
}
#if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS)
ControlBarCleanUp();
#endif
// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
// 而不是启动应用程序的消息泵。
return FALSE;
}

// HGImgFmtTest.h: PROJECT_NAME 应用程序的主头文件
//
#pragma once
#ifndef __AFXWIN_H__
#error "在包含此文件之前包含 'pch.h' 以生成 PCH"
#endif
#include "resource.h" // 主符号
// CHGImgFmtTestApp:
// 有关此类的实现,请参阅 HGImgFmtTest.cpp
//
class CHGImgFmtTestApp : public CWinApp
{
public:
CHGImgFmtTestApp();
// 重写
public:
virtual BOOL InitInstance();
// 实现
DECLARE_MESSAGE_MAP()
};
extern CHGImgFmtTestApp theApp;
B// Microsoft Visual C++ generated resource script.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{BDAF5148-EE35-458B-99EB-2E0C1D8631AC}</ProjectGuid>
<Keyword>MFCProj</Keyword>
<RootNamespace>HGImgFmtTest</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="HGImgFmtTest.h" />
<ClInclude Include="HGImgFmtTestDlg.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="HGImgFmtTest.cpp" />
<ClCompile Include="HGImgFmtTestDlg.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="HGImgFmtTest.rc" />
</ItemGroup>
<ItemGroup>
<None Include="res\HGImgFmtTest.rc2" />
</ItemGroup>
<ItemGroup>
<Image Include="res\HGImgFmtTest.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="HGImgFmtTest.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="HGImgFmtTestDlg.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="framework.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="pch.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="HGImgFmtTest.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="HGImgFmtTestDlg.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="HGImgFmtTest.rc">
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="res\HGImgFmtTest.rc2">
<Filter>资源文件</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Image Include="res\HGImgFmtTest.ico">
<Filter>资源文件</Filter>
</Image>
</ItemGroup>
</Project>
\ No newline at end of file

// HGImgFmtTestDlg.cpp: 实现文件
//
#include "pch.h"
#include "framework.h"
#include "HGImgFmtTest.h"
#include "HGImgFmtTestDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_ABOUTBOX };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CHGImgFmtTestDlg 对话框
CHGImgFmtTestDlg::CHGImgFmtTestDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_HGIMGFMTTEST_DIALOG, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CHGImgFmtTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CHGImgFmtTestDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()
// CHGImgFmtTestDlg 消息处理程序
BOOL CHGImgFmtTestDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 将“关于...”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != nullptr)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
HGImgFmtReader reader;
HGImgFmt_OpenImageReader("D:\\1.ofd", 0, &reader);
HGImgFmtWriter writer = NULL;
HGImgFmt_OpenImageWriter("D:\\222.ofd", 0, &writer);
HGUInt count;
HGImgFmt_GetImagePageCount(reader, &count);
for (HGUInt i = 0; i < count; ++i)
{
HGImage image = NULL;
HGImgFmt_LoadImageFromReader(reader, i, NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &image);
if (NULL != image)
{
HGImgFmt_SaveImageToWriter(writer, image, NULL);
HGBase_DestroyImage(image);
}
}
HGImgFmt_CloseImageWriter(writer);
HGImgFmt_CloseImageReader(reader);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void CHGImgFmtTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CHGImgFmtTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CHGImgFmtTestDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}

// HGImgFmtTestDlg.h: 头文件
//
#pragma once
// CHGImgFmtTestDlg 对话框
class CHGImgFmtTestDlg : public CDialogEx
{
// 构造
public:
CHGImgFmtTestDlg(CWnd* pParent = nullptr); // 标准构造函数
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_HGIMGFMTTEST_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
HICON m_hIcon;
// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
};
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 由 HGImgFmtTest.rc 使用
//
#define IDR_MAINFRAME 128
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_HGIMGFMTTEST_DIALOG 102
// 新对象的下一组默认值
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 32771
#endif
#endif
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的
// 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息
#define _AFX_ALL_WARNINGS
#include <afxwin.h> // MFC 核心组件和标准组件
#include <afxext.h> // MFC 扩展
#include <afxdisp.h> // MFC 自动化类
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC 对 Internet Explorer 4 公共控件的支持
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC 对 Windows 公共控件的支持
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxcontrolbars.h> // MFC 支持功能区和控制条
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
// pch.cpp: 与预编译标头对应的源文件
#include "pch.h"
// 当使用预编译的头时,需要使用此源文件,编译才能成功。
#ifdef _WIN64
#ifdef _DEBUG
#pragma comment(lib, "../x64/Debug/HGImgFmt.lib")
#else
#pragma comment(lib, "../x64/Release/HGImgFmt.lib")
#endif
#pragma comment(lib, "../../../release/lib/windows/x64/HGBase.lib")
#else
#ifdef _DEBUG
#pragma comment(lib, "../Debug/HGImgFmt.lib")
#else
#pragma comment(lib, "../Release/HGImgFmt.lib")
#endif
#pragma comment(lib, "../../../release/lib/windows/x86/HGBase.lib")
#endif
// pch.h: 这是预编译标头文件。
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
#ifndef PCH_H
#define PCH_H
// 添加要在此处预编译的标头
#include "framework.h"
#include "../../HGJpeg.h"
#include "../../HGBmp.h"
#include "../../HGPng.h"
#include "../../HGTiff.h"
#include "../../HGPdf.h"
#include "../../HGOfd.h"
#include "../../HGImgFmt.h"
#include "../../../release/include/base/HGBase.h"
#endif //PCH_H
#pragma once
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
//如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>
......@@ -4,4 +4,42 @@
#include "HGDef.h"
#include "HGBaseErr.h"
/* 获取系统临时文件目录
*/
HGEXTERN_C HGResult HGAPI HGBase_GetTmpPath(HGChar* path, HGUInt maxLen);
/* 获取进程的当前工作目录
*/
HGEXTERN_C HGResult HGAPI HGBase_GetCurrentDir(HGChar* dir, HGUInt maxLen);
/* 设置进程的当前工作目录
*/
HGEXTERN_C HGResult HGAPI HGBase_SetCurrentDir(const HGChar* dir);
/* 创建目录
* 该函数可以创建多级目录
*/
HGEXTERN_C HGResult HGAPI HGBase_CreateDir(const HGChar* dir);
/* 删除目录
* 该函数只能用于删除空目录
*/
HGEXTERN_C HGResult HGAPI HGBase_DeleteDir(const HGChar* dir);
/* 删除文件
*/
HGEXTERN_C HGResult HGAPI HGBase_DeleteFile(const HGChar* fileName);
/* 获取模块名称
*/
HGEXTERN_C HGResult HGAPI HGBase_GetModuleName(HGPointer addr, HGChar* name, HGUInt maxLen);
/* 获取UUID
*/
HGEXTERN_C HGResult HGAPI HGBase_GetUuid(HGChar* uuid, HGUInt maxLen);
/* 获取临时文件名
*/
HGEXTERN_C HGResult HGAPI HGBase_GetTmpFileName(HGChar* fileName, HGUInt maxLen);
#endif /* __HGUTILITY_H__ */
\ No newline at end of file
......@@ -84,12 +84,12 @@ HGEXTERN_C HGResult HGAPI HGTwain_SelectDS(HGTwainDSM dsm, HGTwainDS* ds);
* 1) dsm: in, DSM句柄
* 2) ds: in, DS句柄
* 3) name: out, DS名字数据区地址
* 4) size: in, out, DS名字数据区长度/DS名字长度
* 4) maxLen: in, DS名字数据区长度
* 说明:
* 1) 该函数需要TWAIN状态为3
* 2) size既作为输入, 也作为输出, 返回的size包括空字符
*/
HGEXTERN_C HGResult HGAPI HGTwain_GetDSName(HGTwainDSM dsm, HGTwainDS ds, HGChar *name, HGUInt *size);
HGEXTERN_C HGResult HGAPI HGTwain_GetDSName(HGTwainDSM dsm, HGTwainDS ds, HGChar *name, HGUInt maxLen);
/* 打开DS
* 参数:
......
......@@ -93,7 +93,7 @@ HGResult HGAPI HGTwain_SelectDS(HGTwainDSM dsm, HGTwainDS* ds)
return twainImpl->SelectDS(ds);
}
HGResult HGAPI HGTwain_GetDSName(HGTwainDSM dsm, HGTwainDS ds, HGChar* name, HGUInt* size)
HGResult HGAPI HGTwain_GetDSName(HGTwainDSM dsm, HGTwainDS ds, HGChar* name, HGUInt maxLen)
{
if (NULL == dsm)
{
......@@ -101,7 +101,7 @@ HGResult HGAPI HGTwain_GetDSName(HGTwainDSM dsm, HGTwainDS ds, HGChar* name, HGU
}
HGTwainImpl* twainImpl = (HGTwainImpl*)dsm;
return twainImpl->GetDSName(ds, name, size);
return twainImpl->GetDSName(ds, name, maxLen);
}
HGResult HGAPI HGTwain_OpenDS(HGTwainDSM dsm, HGTwainDS ds)
......
......@@ -84,12 +84,12 @@ HGEXTERN_C HGResult HGAPI HGTwain_SelectDS(HGTwainDSM dsm, HGTwainDS* ds);
* 1) dsm: in, DSM句柄
* 2) ds: in, DS句柄
* 3) name: out, DS名字数据区地址
* 4) size: in, out, DS名字数据区长度/DS名字长度
* 4) maxLen: in, DS名字数据区长度
* 说明:
* 1) 该函数需要TWAIN状态为3
* 2) size既作为输入, 也作为输出, 返回的size包括空字符
*/
HGEXTERN_C HGResult HGAPI HGTwain_GetDSName(HGTwainDSM dsm, HGTwainDS ds, HGChar *name, HGUInt *size);
HGEXTERN_C HGResult HGAPI HGTwain_GetDSName(HGTwainDSM dsm, HGTwainDS ds, HGChar *name, HGUInt maxLen);
/* 打开DS
* 参数:
......
......@@ -211,9 +211,9 @@ HGResult HGTwainImpl::SelectDS(HGTwainDS* ds)
return HGBASE_ERR_FAIL;
}
HGResult HGTwainImpl::GetDSName(HGTwainDS ds, HGChar* name, HGUInt* size)
HGResult HGTwainImpl::GetDSName(HGTwainDS ds, HGChar* name, HGUInt maxLen)
{
if (NULL == ds || NULL == name || NULL == size || 0 == *size)
if (NULL == ds || NULL == name || 0 == maxLen)
{
return HGBASE_ERR_INVALIDARG;
}
......@@ -227,8 +227,7 @@ HGResult HGTwainImpl::GetDSName(HGTwainDS ds, HGChar* name, HGUInt* size)
{
if (ds == (HGTwainDS)&m_DSList[i])
{
strcpy_s(name, *size, m_DSList[i].ds.ProductName);
*size = (HGUInt)strlen(name) + 1;
strcpy_s(name, maxLen, m_DSList[i].ds.ProductName);
return HGBASE_ERR_OK;
}
}
......
......@@ -36,7 +36,7 @@ public:
HGResult GetDSList(HGTwainDS* ds, HGUInt* size);
HGResult GetDefaultDS(HGTwainDS* ds);
HGResult SelectDS(HGTwainDS* ds);
HGResult GetDSName(HGTwainDS ds, HGChar* name, HGUInt* size);
HGResult GetDSName(HGTwainDS ds, HGChar* name, HGUInt maxLen);
HGResult OpenDS(HGTwainDS ds);
HGResult CloseDS(HGTwainDS ds);
HGResult SetCapability(HGTwainDS ds, HGUInt cap, HGInt value);
......
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