You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
6.5 KiB
C++

//////////////////////////////////////////////////////////////////////////////
//文件: 格式转换类
//主要功能:
// 读取EMF格式
//
//程序编写: 2024-10-20
//
//GIT :https://github.com/mathog/libUEMF.git
/////////////////////////////////////////////////////////////////////////////
#pragma once
#include ".\otherformat.h"
#include "afxcoll.h"
#include "uemf.h"
#include "uemf_print.h"
#include "upmf.h"
#include "uemf_utf.h"
#include "uemf_safe.h"
#include "uemf_endian.h"
#include ".\DrawOperator\Utils.h"
#include ".\DrawOperator\EmfDefine.h"
namespace NFormatReader
{
class CEmfFile :
public COtherFormat
{
public:
CEmfFile(void);
virtual ~CEmfFile(void);
int Read(LPCTSTR lpszPathName);
int Read(CFile& fr);
protected:
//元素信息
int ReadEMFArc(double sx, double sy, double ax, double ay, double angle, DWORD type, PEMF_CALLBACK_DATA d);
int ReadEMFLine(const CList<EMRLINETOS, EMRLINETOS>& list, PEMF_CALLBACK_DATA d);
int ReadEMFLine_EMR_POLYGON16(const CList<EMRLINETOS, EMRLINETOS>& list, PEMF_CALLBACK_DATA d);
int ReadEMFEllipse(double cx, double cy, double rx, double ry, COLORREF color);
int ReadEMFPolyLine(const CList<EMRLINETOS, EMRLINETOS>& list, PEMF_CALLBACK_DATA d);
int ReadEMFClipPolyLine(const CList<EMRLINETOS, EMRLINETOS>& list, PEMF_CALLBACK_DATA d);
int ReadEMFPolyLine_EMR_POLYPOLYLINE16(const CList<EMRLINETOS, EMRLINETOS>& list, PEMF_CALLBACK_DATA d);
int ReadEMFText(const TCHUNK_SPECS &tsp, char * textString, char *fontspec, PEMF_CALLBACK_DATA d);
int ReadEMFPolyBezierto(const CList<EMRLINETOS, EMRLINETOS>& list, PEMF_CALLBACK_DATA d);
int ReadEMFPolyBezierto_EMR_POLYBEZIERTO16(const CList<EMRLINETOS, EMRLINETOS>& list, PEMF_CALLBACK_DATA d);
int ReadEMFImage(CRect8 rect, const CString &imagePath);
int ReadEMFRect(CRect8 rect, PEMF_CALLBACK_DATA d);
int ReadEMFDraw(PEMF_CALLBACK_DATA d);
virtual POSITION AddElement(void* pElement, int type);
int AI_hack(PU_EMRHEADER pEmr);
//EMF文件属性读取
int myEnhMetaFileProc(char *contents, unsigned int length, PEMF_CALLBACK_DATA d);
//裁剪区域填充
void enlarge_clips(PEMF_CALLBACK_DATA d);
int in_clips(PEMF_CALLBACK_DATA d, const char* test);
void add_clips(PEMF_CALLBACK_DATA d, const char* clippath, unsigned int logic);
int combine_ops_to_livarot(const int op);
void output_style(PEMF_CALLBACK_DATA d, int iType);
//坐标转换
double pix_to_x_point(PEMF_CALLBACK_DATA d, double px, double py);
double pix_to_y_point(PEMF_CALLBACK_DATA d, double px, double py);
double _pix_x_to_point(PEMF_CALLBACK_DATA d, double px);
double _pix_y_to_point(PEMF_CALLBACK_DATA d, double py);
double pix_to_abs_size(PEMF_CALLBACK_DATA d, double px);
void snap_to_faraway_pair(double *x, double *y);
int trinfo_load_bk(TR_INFO *tri, int usebk, TRCOLORREF bkcolor);
int trinfo_check_bk(TR_INFO *tri, int usebk, TRCOLORREF bkcolor);
void delete_object(PEMF_CALLBACK_DATA d, int index);
void insert_object(PEMF_CALLBACK_DATA d, int index, int type, PU_ENHMETARECORD pObj);
int trinfo_load_qe(TR_INFO *tri, double qe);
double current_scale(PEMF_CALLBACK_DATA d);
void select_pen(PEMF_CALLBACK_DATA d, int index);
void select_extpen(PEMF_CALLBACK_DATA d, int index);
void select_brush(PEMF_CALLBACK_DATA d, int index);
void select_font(PEMF_CALLBACK_DATA d, int index);
uint32_t *unknown_chars(size_t count);
int isNon(char *font);
void msdepua(uint32_t *text);
int NonToUnicode(uint32_t *text, char *font);
COLORREF sethexcolor(TRCOLORREF color);
COLORREF sethexcolor(U_COLORREF color);
U_COLORREF gethexcolor(uint32_t color);
COLORREF getRGBAColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
double current_rotation(PEMF_CALLBACK_DATA d);
void enlarge_hatches(PEMF_CALLBACK_DATA d);
int in_hatches(PEMF_CALLBACK_DATA d, char *test);
uint32_t add_image(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t cbBits, uint32_t cbBmi,
uint32_t iUsage, uint32_t offBits, uint32_t offBmi);
uint32_t add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hatchColor);
void free_emf_strings(EMF_STRINGS name);
void common_image_extraction(PEMF_CALLBACK_DATA d, void *pEmr,
double dx, double dy, double dw, double dh, int sx, int sy, int sw, int sh,
uint32_t iUsage, uint32_t offBits, uint32_t cbBits, uint32_t offBmi, uint32_t cbBmi, U_RECTL rc);
std::string GenerateUniqueFilename(const std::string& baseName, const std::string& extension);
bool Save_RGBA_As_BMP(const std::string &ename, std::unique_ptr<char[]> rgba_data, uint32_t width, uint32_t height);
int RemovePathFile();
bool IsOutsideModelSpace(double x0, double y0, const CRect8 &rect); //处理不合理坐标值
std::list<EMRLINETOS> FilterPointsInRect(PEMF_CALLBACK_DATA d, const std::list<EMRLINETOS>& points, bool state);
std::list<EMRLINETOS> FilterPointsInRect(PEMF_CALLBACK_DATA d, const std::list<EMRLINETOS>& points);
private:
CString GetFontName(CString faceName);
int U_EMR_COMMENT_F(PEMF_CALLBACK_DATA d, const char* contents, const char* blimit, int recnum, int off);
//刨面图充填处理
int ReadEMFLine_FillRects(const std::list<EMRLINETOS>& list, PEMF_CALLBACK_DATA d, const CString &str);
//充填
int ReadEMFLine_FillRects(const std::list<EMRLINETOS>& list, PEMF_CALLBACK_DATA d);
//绘制规则图形充填
int ReadEMF_PMR_RectFill(const std::list<EMRLINETOS>& list, PEMF_CALLBACK_DATA d, const CString& str);
//刨面贝塞尔曲线
int ReadEMF_PMR_DrawBeziers(const std::list<EMRLINETOS>& listc, PEMF_CALLBACK_DATA d);
//
int ReadEMF_PMR_RectLine(const std::list<EMRLINETOS>& list, PEMF_CALLBACK_DATA d);
//
int ReadEMF_PMR_Line(const std::list<EMRLINETOS>& list, PEMF_CALLBACK_DATA d);
//
int U_PMR_Object_F(PEMF_CALLBACK_DATA d, const char* contents, const char* blimit, U_OBJ_ACCUM* ObjCont, int term);
int U_PMF_PATH_F(PEMF_CALLBACK_DATA d, const char* contents, const char* blimit);
int U_PMR_DrawBeziers_F(PEMF_CALLBACK_DATA d, const char* contents);
int U_PMF_REGIONNODE_F(PEMF_CALLBACK_DATA d, const char* contents, int Level, const char* blimit);
int U_PMF_REGIONNODECHILDNODES_F(PEMF_CALLBACK_DATA d, const char* contents, int Level, const char* blimit);
int U_PMF_BRUSH_F(PEMF_CALLBACK_DATA d, const char* contents, const char* blimit);
int U_PMR_DRAWLINES_F(PEMF_CALLBACK_DATA d, const char* contents);
protected:
// 使用list记录填充区域
std::list<std::list<EMRLINETOS>> m_FilllineLists_std_list;
struct _CURRENT_ELE {
DWORD m_dwID; //当前元素的句柄ID号
BOOL m_bCurentView; //当前元素的可视状态
COLORREF m_colCurrent; //当前元素的颜色
COLORREF m_bColCurrent; //当前元素背景颜色 (填充使用)
CString m_emfImagePath; // 图片临时生成目录
CRect8 m_rect; //总图大小
};
_CURRENT_ELE m_curElement;
};
};