📄 doc_html.cpp
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// Application Programming Interface //
// //
// Library: SAGA_API //
// //
//-------------------------------------------------------//
// //
// doc_html.cpp //
// //
// Copyright (C) 2005 by //
// Victor Olaya //
// //
//-------------------------------------------------------//
// //
// This file is part of 'SAGA - System for Automated //
// Geoscientific Analyses'. //
// //
// This library is free software; you can redistribute //
// it and/or modify it under the terms of the GNU Lesser //
// General Public License as published by the Free //
// Software Foundation, version 2.1 of the License. //
// //
// This library is distributed in the hope that it will //
// be useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A //
// PARTICULAR PURPOSE. See the GNU Lesser General Public //
// License for more details. //
// //
// You should have received a copy of the GNU Lesser //
// General Public License along with this program; if //
// not, write to the Free Software Foundation, Inc., //
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, //
// USA. //
// //
//-------------------------------------------------------//
// //
// contact: Victor Olaya //
// //
// e-mail: volaya@saga-gis.org //
// //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#include "doc_html.h"
//---------------------------------------------------------
#define GRAPH_WIDTH 700
#define GRAPH_HEIGHT 350
#define MAP_WIDTH 700.
#define MAP_HEIGHT 700.
#define OFFSET_X 50
#define OFFSET_Y 50
//---------------------------------------------------------
#define HTML_CODE_OPENING_1 SG_T("<html>\n<head><title>")
#define HTML_CODE_OPENING_2 SG_T("</title>\n")\
SG_T("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n")\
SG_T("</head>\n")\
SG_T("<body bgcolor=\"#FFFFFF\" text=\"#000000\">\n")
#define HTML_CODE_CLOSING SG_T("</body>\n</html>")
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Doc_HTML::CSG_Doc_HTML(){}
CSG_Doc_HTML::~CSG_Doc_HTML(){}
void CSG_Doc_HTML::Open(const SG_Char *Title)
{
m_sHTMLCode.Clear();
m_sHTMLCode.Append(HTML_CODE_OPENING_1);
m_sHTMLCode.Append(Title);
m_sHTMLCode.Append(HTML_CODE_OPENING_2);
}
bool CSG_Doc_HTML::Save(const SG_Char *Filename)
{
m_sHTMLCode.Append(HTML_CODE_CLOSING);
CSG_File Stream(Filename, SG_FILE_W, false);
if( Stream.is_Open() )
{
Stream.Printf(SG_T("%s"), m_sHTMLCode.c_str());
return true;
}
return false;
}
void CSG_Doc_HTML::AddParagraph(const SG_Char *Text)
{
m_sHTMLCode.Append(SG_T("<p align=\"left\">"));
m_sHTMLCode.Append(Text);
m_sHTMLCode.Append(SG_T("</p>\n"));
}
void CSG_Doc_HTML::AddLineBreak()
{
m_sHTMLCode.Append(SG_T("</br>"));
}
void CSG_Doc_HTML::AddHeader(const SG_Char *Text,
int iOrder)
{
m_sHTMLCode.Append(SG_T("<h"));
m_sHTMLCode.Append(SG_Get_String(iOrder,0));
m_sHTMLCode.Append(SG_T(" align=\"left\">"));
m_sHTMLCode.Append(Text);
m_sHTMLCode.Append(SG_T("</h"));
m_sHTMLCode.Append(SG_Get_String(iOrder,0));
m_sHTMLCode.Append(SG_T(">\n"));
}
void CSG_Doc_HTML::AddHyperlink(const SG_Char *Text,
const SG_Char *URL)
{
m_sHTMLCode.Append(SG_T("<a href=\""));
m_sHTMLCode.Append(URL);
m_sHTMLCode.Append(SG_T("\">\n"));
m_sHTMLCode.Append(Text);
m_sHTMLCode.Append(SG_T("\n</a>"));
}
CSG_String CSG_Doc_HTML::GetHyperlinkCode(const SG_Char *Text,
const SG_Char *URL)
{
CSG_String s;
s.Append(SG_T("<a href=\""));
s.Append(URL);
s.Append(SG_T("\">\n"));
s.Append(Text);
s.Append(SG_T("\n</a>"));
return s;
}
void CSG_Doc_HTML::AddImage(const SG_Char *Filename)
{
m_sHTMLCode.Append(SG_T("<img src=\""));
m_sHTMLCode.Append(Filename);
m_sHTMLCode.Append(SG_T("\">\n"));
}
void CSG_Doc_HTML::AddThumbnail(const SG_Char *Filename,
int iWidth,
bool bIsPercent)
{
m_sHTMLCode.Append(SG_T("<a href=\""));
m_sHTMLCode.Append(Filename);
m_sHTMLCode.Append(SG_T("\">\n"));
m_sHTMLCode.Append(SG_T("<img src=\""));
m_sHTMLCode.Append(Filename);
m_sHTMLCode.Append(SG_T("\" width="));
m_sHTMLCode.Append(SG_Get_String(iWidth,0));
if (bIsPercent)
{
m_sHTMLCode.Append(SG_T("%"));
}
m_sHTMLCode.Append(SG_T("></a><br><br>\n"));
}
void CSG_Doc_HTML::AddThumbnails(const SG_Char **Filename,
int iImages,
int iThumbnailsPerRow)
{
int i,j;
int iImage = 0;
int iRows = (int)ceil((double)iImages / (double)iThumbnailsPerRow);
int iWidth = (int)(100.0 / (double)iThumbnailsPerRow);
m_sHTMLCode.Append(SG_T("<table width=\"99%\" style=\"background-color:transparent;\" border=0 cellspacing=0 cellpadding=2 >\n"));
for (i=0; i<iRows; i++)
{
m_sHTMLCode.Append(SG_T("<tr>\n"));
for (j=0; j<iThumbnailsPerRow; j++){
m_sHTMLCode.Append(SG_T("<td width=\""));
m_sHTMLCode.Append(SG_Get_String(iWidth));
m_sHTMLCode.Append(SG_T("%\" align=\"center\">"));
AddThumbnail(Filename[iImage], 100, true);
iImage++;
if (iImage >= iImages){
break;
}
m_sHTMLCode.Append(SG_T("</td>"));
}
m_sHTMLCode.Append(SG_T("\n</tr>\n"));
}
m_sHTMLCode.Append(SG_T("\n</table>\n"));
}
void CSG_Doc_HTML::StartUnorderedList()
{
m_sHTMLCode.Append(SG_T("<ul>\n"));
}
void CSG_Doc_HTML::StartOrderedList()
{
m_sHTMLCode.Append(SG_T("<ol>\n"));
}
void CSG_Doc_HTML::CloseUnorderedList()
{
m_sHTMLCode.Append(SG_T("</ul>\n"));
}
void CSG_Doc_HTML::CloseOrderedList()
{
m_sHTMLCode.Append(SG_T("</ol>\n"));
}
void CSG_Doc_HTML::AddListElement(const SG_Char *Text)
{
m_sHTMLCode.Append(SG_T("<li>"));
m_sHTMLCode.Append(Text);
m_sHTMLCode.Append(SG_T("</li>\n"));
}
void CSG_Doc_HTML::AddOrderedList(const SG_Char **Text, int iElements)
{
StartOrderedList();
for (int i = 0; i < iElements; i++)
{
AddListElement(Text[i]);
}
CloseOrderedList();
}
void CSG_Doc_HTML::AddUnorderedList(const SG_Char **Text, int iElements)
{
StartUnorderedList();
for (int i = 0; i < iElements; i++)
{
AddListElement(Text[i]);
}
CloseUnorderedList();
}
void CSG_Doc_HTML::AddCurve(const SG_Char *Filename,
CSG_Points &Data,
const SG_Char *Description,
int iGraphType,
bool bIncludeTableData)
{
int i;
int iMag;
int iNumLines;
double fMinLine = 0;
double fWidth;
double fMax, fMin;
double fRange, fRangeX;
double fStep;
double fX, fY, fY2;
double fMaxX, fMinX;
CSG_String sValue;
CSG_String sTableFilename;
CSG_Points Points;
CSG_Doc_SVG SVG;
m_sHTMLCode.Append(SG_T("<object type=\"image/svg+xml\" width=\""));
m_sHTMLCode.Append(SG_Get_String(GRAPH_WIDTH + OFFSET_X, 0));
m_sHTMLCode.Append(SG_T("\" height=\""));
m_sHTMLCode.Append(SG_Get_String(GRAPH_HEIGHT + OFFSET_Y, 0));
m_sHTMLCode.Append(SG_T("\" data=\"file://"));
m_sHTMLCode.Append(Filename);
m_sHTMLCode.Append(SG_T("\"></object><br>\n"));
m_sHTMLCode.Append(SG_T("<p align=\"center\"><i>"));
m_sHTMLCode.Append(Description);
m_sHTMLCode.Append(SG_T("</i></p>\n"));
fMin = fMax = Data[0].y;
for (i = 0; i < Data.Get_Count(); i++)
{
if (Data[i].y > fMax)
{
fMax = Data[i].y;
}
if (Data[i].y < fMin)
{
fMin = Data[i].y;
}
if (iGraphType == HTML_GRAPH_TYPE_BARS){
fMin = M_GET_MIN(0, fMin);
}
}
fRange = fMax - fMin;
fMaxX = Data[Data.Get_Count() - 1].x;
fMinX = Data[0].x;
fRangeX = fMaxX - fMinX;
SVG.Open(GRAPH_WIDTH + OFFSET_X, GRAPH_HEIGHT + OFFSET_Y);
if (fMin != fMax){
iMag = (int) (log(fMax - fMin) / log(10.0));
fStep = (int) pow(10.0, (double) iMag);
if (fStep == 0)
{
fStep = 1.;
}
if (fMin < 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -