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.

227 lines
6.7 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//////////////////////////////////////////////////////////////////////////////
//文件 CPdfDraw.h
//主要功能:
//
//程序编写:
/////////////////////////////////////////////////////////////////////////////
#pragma once
#include "formatdc.h"
#include "../IDcDraw.h"
#ifndef M_PI
# define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef M_PI_2
#define M_PI_2 (M_PI / 2.0)
#endif
#include "cairo/cairo.h"
#include "cairo/cairo-pdf.h"
#include <unordered_map>
class CPdfDraw :
public IDcDraw
{
public:
typedef struct
{
double x; //线段点的x
double y; //线段点的y
COLORREF Color; //记录线段色彩
}CAIROPOINT;
enum class CairoFitMode
{
Center = 0, // 居中
FitToPage = 1 // 按比例最大适应(缩放)
};
enum class CairoSize
{
Cairo_A3 = 0,
Cairo_A4 = 1,
Cairo_A5 = 2,
Cairo_B4 = 3
};
public:
CPdfDraw();
CPdfDraw(CXyDC* pXyDC);
~CPdfDraw();
void Create(CXyDC* pXyDC);
void InitDC();
void ReleaseDC();
void Close();
void SetPdfData(CXy* pXy);
void SetPdfFilePath(const CString &path);
void SetPdfNumber(int num);
void Draw(CText& text, CCurveEx* pCurveRect = NULL); //当pCurveRect不为空时表示仅是为了获得显示范围
void Draw(CText& text, COLORREF color); //-文字
void Draw(CMText& mtext);
void Draw(CEllipse& elp, COLORREF Color);
void Draw(CCircle& circle, COLORREF Color);
void Draw(CInsertDraw& m_insert); //-符号井(特殊符号 组合)
void Draw(CXyDC* pNewXyDC, CInsertDraw& m_insert);
void Draw(CInsertOld& m_insert);
void Draw(CXyDC* pInsertXyDC, CInsertOld& m_insert);
void Draw(CSection& section, CRect8* rect = NULL);
void Draw(CImageInsert& image); //-背景
void Draw(CMesh& mesh);
void Draw(CMetaFile& mf);
void Draw(CColorRuler& ruler, CColorBase& color); //-色标
void Draw(CPathFill& path, COLORREF fillColor, void* HowToViewCurve);
void Draw(C3DFaultageSurface& fs, COLORREF fillColor, void* HowToViewCurve);
void Draw(CProportion& proportion, COLORREF color); //-比例尺
void Draw(CCurveEx& curve, double l1, double l2);
void Draw(CCurveEx& m_curve);
void Draw(CCurveEx& curve, void* HowToViewCurve); //-修饰线
void Draw(CCurveEx& curve, COLORREF color, BOOL bSmoothHead = TRUE);//-线
void DrawVirtualCairo(CCurveEx &curve, CCurveProperties *type); //虚线
void Draw(CCurveRect& rt, void* HowToViewCurve);
void Draw(CCurveRect& curve, COLORREF color);
void Draw(CPointNameEx& point, void* HowToViewPoint); //-符号井
void Draw(CPointCrossName& point, void* HowToViewPoint);
void Draw(CPointTwoName& point, void* HowToViewPoint);
void Draw(CInsertDrawRect& idr);//-
void Draw(CArc& arc, void* HowToViewCurve);//-
void Draw(CArc& arc, COLORREF color);//-
void Draw(CFrame& frame, COLORREF color); //- 边框(不处理)
void Draw(CNet& net, COLORREF colText, COLORREF colLine);
void Draw(CGridding& grid, COLORREF colText, COLORREF colLine); //- 边框经纬网(不处理)
void Draw(COtherDraw& od, void* HowToViewCurve);
void Draw(COtherDraw& od, COLORREF color);
void Draw(COleObject& ole);
void Draw(CTree& tree);
void Draw(CStation& cs);
void Draw(CCurveTV5& tv, void* HowToViewCurve);
void Draw(CScaleRuler& sr, COLORREF color);
void Draw(CRectLabel& rl, COLORREF color, void* HowToViewCurve);
void DrawArray(CMxn& mxn, COLORREF colFront, COLORREF colBack); //前景色与背景色
void Draw(CMxn& mxn, COLORREF colFront, COLORREF colBack);
void DrawGrid(CMxn& mxn);
void Draw(CHorizontalWell& horizontalwell, void* HowToViewCurve);
void Draw(CWellGroup& wellGroup);
void PolyLine(CPointList& dp);
void PaintRgn(LPPOINT sp, int count);
//绘制等值线及其名称
void DrawPolylineName(const vector<CAIROPOINT>& points, const CString &name, double text_h, double position_distance = -1.0);
void SetMargins(double left, double right, double top, double bottom);
void SetLandscape(int isLandscape);
void SetFitMode(CairoFitMode mode);
void SetPDFSize(CairoSize type);
void SetPDFCairo(void *pCairo, bool state);
private:
void Clear();
//设置颜色
void SetCairoColorFromCOLORREF(cairo_t* cr, COLORREF color, double alpha = 1);
//坐标映射到A4
void Map_Coordinates(cairo_t* cr, double externalWidth, double externalHeight, double A4Width, double A4Height);
//将角度转换为弧度
double DegreesToRadians(double degrees);
uint8_t* LoadBMPToARGBData(const char* filePath, uint32_t& width, uint32_t& height);
//查询元素对应的COne
COne* FindElementMap(void* pValue);
//文字绘制
void DrawCairoText(CText& text, COLORREF color);
//文字带有角度处理
void DrawCairoTextAngle(CText &text, COLORREF color);
//文字换行显示(Cairo不支持"\r\n" "\n")
void DrawCairoMultilineText(CText& text, COLORREF color);
//文字竖向显示横向文字偏转90°
void DrawCairoVerticalText(CText& text, COLORREF color);
//矩形充填绘制
void DrawCairoFillRect(CRect8& rect, COLORREF color);
//绘制线段
void DrawCairoLine(std::vector<CAIROPOINT>& pointVec, COLORREF color = 0);
//色标绘制
void DrawCairoRulerImage(CColorRuler& ruler, CColorBase &color);
//绘制缺省符号
void DrawOther(double x0, double y0, CSize8 sz, COLORREF col, UINT nMode, double a);
//添加pdf页码
void DrawCairoAddPdfNumber();
//
void DrawCairoCurveMark(CCurveEx &curve);
//计算线段名字属性位置
void ComputeCurveName(CCurveEx &curve, CCurveName *pName, int state);
//计算距离
double DistancePolyLine(const CAIROPOINT& p1, const CAIROPOINT& p2);
//计算距离
double TotalLengthPolyLine(const std::vector<CAIROPOINT>& points);
//获取多边形质心
CPoint2D GetPolygonCentroid(const CCurveEx& curve, CXyDC* pXyDc);
//横向文字分割成单个
std::vector<std::string> StringSplit(const std::string& str);
/**
* 将上下标字符转换
*
* \param cmd
* \return 转换后的字符
*/
CString ReverseSuperAndSubConversion(CString cmd);
//设置折线平滑 插值
void DrawSmoothPathUsingInterpolation(
cairo_t* cr,
double* x,
double* y,
int count,
int samplesPerSegment = 20);
/**
* 处理两个闭合多边形的交点集充填 处理透明充填问题
*
* \param polysA 多边形集合
* \param curPoly 当前多边形
*/
void FillIntersection(
const std::vector<std::vector<CAIROPOINT>>& polysA,
std::vector<CAIROPOINT>& curPoly);
//背景
void DrawCairoImageInsert(CImageInsert& image);
private:
cairo_t* p_cairo;
cairo_surface_t* p_surface;
bool m_symbolstate; //绘制pdf符号线段线宽使用
double m_scale;
CSize8 m_paperSize; //图纸宽高mm(A4)
CRect8 m_rect;
CSize8 m_unit;
CRect8 m_paperMargin; //边距(单位是 point72 point = 1英寸
int m_landscape; //0自适应, 1为纵向 2横向
int m_number; //页码
CairoFitMode m_fitMode;
CString m_filePath;
std::unordered_map<void*, COne*> m_elementMap;
std::shared_ptr<CXyDC> m_cacheXyDC; //单独显示符号
std::shared_ptr<CXyDC> m_cacheOldXyDC; //单独显示符号
std::shared_ptr<CXyDC> m_symbolXyDC; //充填符号单独绘制
std::vector<std::vector<CAIROPOINT>> m_polygons; //记录多边个数
};