📄 doc_pdf.cpp
字号:
}
break;
case PDF_TITLE_02:
if( m_pLastLevel1OutlineItem )
{
pOutlineItem = m_pLastLevel2OutlineItem = new PdfOutlineItem(m_pLastLevel1OutlineItem);
}
break;
case PDF_TITLE_NONE:
if( m_pLastLevel2OutlineItem )
{
pOutlineItem = new PdfOutlineItem(m_pLastLevel2OutlineItem);
}
break;
}
if( pOutlineItem )
{
pOutlineItem ->SetTitle(SG_STR_SGTOMB(Title));
if( pPage )
{
PdfDestination *pDestination;
pDestination = new PdfDestination(pPage);
pDestination ->SetFit();
pOutlineItem ->SetDestination(pDestination);
}
return( true );
}
}
return( false );
}
//---------------------------------------------------------
bool CSG_Doc_PDF::Add_Outline_Item(const SG_Char *Title)
{
return( _Add_Outline_Item(Title, m_pPage, _Get_Lowest_Level_Outline_Item()) );
}
//---------------------------------------------------------
TSG_PDF_Title_Level CSG_Doc_PDF::_Get_Lowest_Level_Outline_Item(void)
{
if( m_pLastLevel2OutlineItem )
{
return( PDF_TITLE_NONE );
}
else if( m_pLastLevel1OutlineItem )
{
return( PDF_TITLE_02 );
}
else if( m_pLastLevel0OutlineItem )
{
return( PDF_TITLE_01 );
}
return( PDF_TITLE );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CSG_Doc_PDF::Add_Page(void)
{
return( Add_Page(m_Size_Paper.Get_XRange(), m_Size_Paper.Get_YRange()) );
}
//---------------------------------------------------------
bool CSG_Doc_PDF::Add_Page(TSG_PDF_Page_Size Size, int Orientation)
{
if (Add_Page())
{
return (Set_Size_Page(Size, Orientation));
}
else
{
return false;
}
}
//---------------------------------------------------------
bool CSG_Doc_PDF::Add_Page(double Width, double Height)
{
if( m_pPDF )
{
m_nPages++;
m_pPage = m_pPDF->AddPage();
Set_Size_Page(Width, Height);
Set_Size_Page(m_Size_Paper.Get_XRange(), m_Size_Paper.Get_YRange());
m_pCanvas = m_pPage->Canvas();
m_pCanvas ->SetRGBStroke ( 0, 0, 0);
m_pCanvas ->SetRGBFill (255, 255, 255);
return( true );
}
return( false );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CSG_Doc_PDF::Set_Size_Page(TSG_PDF_Page_Size Size, int Orientation)
{
double Width, Height;
switch( Size )
{
case PDF_PAGE_SIZE_A4: default:
Width = PDF_PAGE_WIDTH_A4;
Height = PDF_PAGE_HEIGHT_A4;
break;
case PDF_PAGE_SIZE_A3:
Width = PDF_PAGE_WIDTH_A3;
Height = PDF_PAGE_HEIGHT_A3;
break;
}
//-----------------------------------------------------
if( Orientation == PDF_PAGE_ORIENTATION_LANDSCAPE )
{
double a;
a = Width;
Width = Height;
Height = a;
}
return( Set_Size_Page(Width, Height) );
}
//---------------------------------------------------------
bool CSG_Doc_PDF::Set_Size_Page(double Width, double Height)
{
if( (Width > 0.0 && Height > 0.0) )
{
m_Size_Paper .Assign(0.0, 0.0, Width, Height);
m_Size_Margins = m_Size_Paper;
m_Size_Margins.Deflate(10.0, false);
_Layout_Set_Boxes();
if( m_pPage )
{
m_pPage->SetSize((int)m_Size_Paper.Get_XRange(), (int)m_Size_Paper.Get_YRange());
}
}
return( true );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CSG_Doc_PDF::Add_Page_Title(const SG_Char *Title, TSG_PDF_Title_Level Level, TSG_PDF_Page_Size Size, int Orientation)
{
bool bLine, bDestination, bPage;
int FontSize;
//-----------------------------------------------------
if( Add_Page() )
{
if( m_nPages % 2 - 1 )
{
Add_Page();
}
if( Size != PDF_PAGE_SIZE_PREVIOUS || Orientation != PDF_PAGE_ORIENTATION_PREVIOUS )
{
Set_Size_Page(Size, Orientation);
}
//-------------------------------------------------
switch( Level )
{
case PDF_TITLE:
FontSize = 26;
bLine = true;
bDestination = true;
bPage = true;
break;
case PDF_TITLE_01:
FontSize = 22;
bLine = true;
bDestination = false;
bPage = true;
break;
case PDF_TITLE_02:
FontSize = 20;
bLine = false;
bDestination = false;
bPage = false;
break;
}
_Add_Outline_Item(Title, m_pPage, Level);
//-------------------------------------------------
Draw_Text(Get_Margins().Get_XCenter(), Get_Margins().Get_YCenter(), Title, FontSize, PDF_STYLE_TEXT_ALIGN_H_CENTER, 0.0, SG_GET_RGB(0, 0, 0));
//-------------------------------------------------
if( bLine )
{
double y = Get_Margins().Get_YCenter() - 25.0;
Draw_Line(Get_Margins().Get_XMin(), y, Get_Margins().Get_XMax(), y, 5, SG_GET_RGB(0, 0, 0), PDF_STYLE_LINE_END_ROUND);
}
if( bDestination )
{
PdfDestination *pDestination = new PdfDestination(m_pPage);
pDestination->SetFit();
m_pPDF->Catalog()->SetOpenAction(pDestination);
}
if( bPage )
{
Add_Page();
}
return( true );
}
return( false );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CSG_Doc_PDF::_Set_Style_FillStroke(int Style, int Fill_Color, int Line_Color, int Line_Width)
{
if( Is_Ready_To_Draw() )
{
if( Style & PDF_STYLE_POLYGON_STROKE )
{
if( Style & PDF_STYLE_LINE_END_ROUND )
{
m_pCanvas->SetLineCap(PDF_ROUND_END);
}
else if( Style & PDF_STYLE_LINE_END_SQUARE )
{
m_pCanvas->SetLineCap(PDF_PROJECTING_SCUARE_END);
}
else // if( Style & PDF_STYLE_LINE_END_BUTT )
{
m_pCanvas->SetLineCap(PDF_BUTT_END);
}
if( Style & PDF_STYLE_LINE_JOIN_ROUND )
{
m_pCanvas->SetLineJoin(PDF_ROUND_JOIN);
}
else if( Style & PDF_STYLE_LINE_JOIN_BEVEL )
{
m_pCanvas->SetLineJoin(PDF_BEVEL_JOIN);
}
else // if( Style & PDF_STYLE_LINE_JOIN_MITER )
{
m_pCanvas->SetLineJoin(PDF_MITER_JOIN);
}
m_pCanvas->SetRGBStroke(SG_GET_R(Line_Color), SG_GET_G(Line_Color), SG_GET_B(Line_Color));
m_pCanvas->SetLineWidth(Line_Width);
}
//-------------------------------------------------
if( Style & PDF_STYLE_POLYGON_FILL )
{
m_pCanvas->SetRGBFill(SG_GET_R(Fill_Color), SG_GET_G(Fill_Color), SG_GET_B(Fill_Color));
}
return( true );
}
return( false );
}
//---------------------------------------------------------
bool CSG_Doc_PDF::Draw_Point(double x, double y, double Width, int Style, int Fill_Color, int Line_Color, int Line_Width)
{
if( Is_Ready_To_Draw() )
{
Width /= 2.0;
//-------------------------------------------------
// if( Style & PDF_STYLE_POINT_CIRCLE )
{
}
// else // if( Style & PDF_STYLE_POINT_SQUARE )
{
return( Draw_Rectangle(x - Width, y - Width, x + Width, y + Width, Style, Fill_Color, Line_Color, Line_Width) );
}
}
return( false );
}
//---------------------------------------------------------
bool CSG_Doc_PDF::Draw_Line(double xa, double ya, double xb, double yb, int Width, int Color, int Style)
{
CSG_Points Points;
Points.Add(xa, ya);
Points.Add(xb, yb);
return( Draw_Line(Points, Width, Color, Style) );
}
bool CSG_Doc_PDF::Draw_Line(CSG_Points &Points, int Width, int Color, int Style)
{
if( Points.Get_Count() > 1 && _Set_Style_FillStroke(Style|PDF_STYLE_POLYGON_STROKE, 0, Color, Width) )
{
m_pCanvas->MoveTo(Points[0].x, Points[0].y);
for(int i=1; i<Points.Get_Count(); i++)
{
m_pCanvas->LineTo(Points[i].x, Points[i].y);
}
//-------------------------------------------------
m_pCanvas->Stroke();
return( true );
}
return( false );
}
//---------------------------------------------------------
bool CSG_Doc_PDF::Draw_Rectangle(double xa, double ya, double xb, double yb, int Style, int Fill_Color, int Line_Color, int Line_Width)
{
CSG_Points Points;
Points.Add(xa, ya);
Points.Add(xb, ya);
Points.Add(xb, yb);
Points.Add(xa, yb);
return( Draw_Polygon(Points, Style, Fill_Color, Line_Color, Line_Width) );
}
bool CSG_Doc_PDF::Draw_Rectangle(const CSG_Rect &r, int Style, int Fill_Color, int Line_Color, int Line_Width)
{
return( Draw_Rectangle(r.Get_XMin(), r.Get_YMin(), r.Get_XMax(), r.Get_YMax(), Style, Fill_Color, Line_Color, Line_Width) );
}
//---------------------------------------------------------
bool CSG_Doc_PDF::Draw_Polygon(CSG_Points &Points, int Style, int Fill_Color, int Line_Color, int Line_Width)
{
if( Points.Get_Count() > 2 && _Set_Style_FillStroke(Style, Fill_Color, Line_Color, Line_Width) )
{
m_pCanvas->MoveTo(Points[0].x, Points[0].y);
for(int i=1; i<Points.Get_Count(); i++)
{
m_pCanvas->LineTo(Points[i].x, Points[i].y);
}
m_pCanvas->ClosePath();
//-------------------------------------------------
if( Style & PDF_STYLE_POLYGON_FILL && Style & PDF_STYLE_POLYGON_STROKE )
{
m_pCanvas->EofillStroke();
}
else if( Style & PDF_STYLE_POLYGON_FILL )
{
m_pCanvas->Eofill();
}
else // if( Style & PDF_STYLE_POLYGON_STROKE )
{
m_pCanvas->Stroke();
}
return( true );
}
return( false );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CSG_Doc_PDF::Draw_Text(double x, double y, CSG_Strings &Text, int Size, int Style, double Angle, int Color, TSG_PDF_Font_Type Font)
{
if( Is_Ready_To_Draw() && Text.Get_Count() > 0 )
{
for(int i=0; i<Text.Get_Count(); i++, y-=Size)
{
_Draw_Text(x, y, Text[i], Size, Style, Angle, Color, Font);
}
return( true );
}
return( false );
}
//---------------------------------------------------------
bool CSG_Doc_PDF::Draw_Text(double x, double y, const SG_Char *Text, int Size, int Style, double Angle, int Color, TSG_PDF_Font_Type Font)
{
int n;
CSG_String String(Text);
CSG_Strings Strings;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -