⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doc_html.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		{
			iMag = (int) (log(fabs(fMin)) / log(10.0));
			fMinLine = -(int) pow(10.0, (double) iMag);
		}
		else
		{
			fMinLine=(int)(((int)(fMin/fStep)) *fStep);
		}

		iNumLines = (int) ((fMax - fMin) / fStep);

		while (iNumLines < 8)
		{
			fStep = fStep / 2.0;
			iNumLines = (int) ((fMax - fMin) / fStep);
		}
		iNumLines = (int) ((fMax - fMinLine) / fStep);
	}
	else{
		if (fMin > 0)
		{
			fStep = fMin = 0;
			iNumLines = 1;
			fMinLine = fMax;
		}
		else if (fMin < 0)
		{
			fStep = 0;
			fMin = fMin - 1;
			fMinLine = fMax;
		}
		else
		{
			return;
		}
	}

	for (i = 0; i < iNumLines; i++)
	{
        fY = (fMinLine + fStep * i - fMin) / (fRange) * GRAPH_HEIGHT;
		fY = GRAPH_HEIGHT - fY;
        if (fY >= 0 && fY <= GRAPH_HEIGHT)
		{
			SVG.Draw_Line(OFFSET_X - 10, fY, GRAPH_WIDTH + OFFSET_X, fY);
			SVG.Draw_Text(OFFSET_X - 10, fY, SG_Get_String(fMinLine + fStep * i, 1), 0, SG_T("Verdana"), 8, SG_T(""), SVG_ALIGNMENT_Right);
        }
    }

	if (iGraphType == HTML_GRAPH_TYPE_BARS)
	{
		fWidth = GRAPH_WIDTH / (double) (Data.Get_Count()) ;
	    for (i = 0; i < Data.Get_Count(); i++)
		{
	        fX = OFFSET_X + i * fWidth;
			fY = GRAPH_HEIGHT;
			fY2 = (Data.Get_Y(i) - fMin) / fRange * GRAPH_HEIGHT;
			fY2 = GRAPH_HEIGHT - fY2;
			SVG.Draw_Rectangle(fX, fY, fX + fWidth, fY2, 0x660000, 0x000000);
	    }
	}
	else
	{
		for (i = 0; i < Data.Get_Count(); i++)
		{
			fX = OFFSET_X + (Data.Get_X(i) - fMinX) / fRangeX * GRAPH_WIDTH;
			fY = (Data.Get_Y(i) - fMin) / fRange * GRAPH_HEIGHT;
			fY = GRAPH_HEIGHT - fY;
			Points.Add(fX, fY);
	    }
		SVG.Draw_Line(Points, 4, SG_T(""), 0x660000);
	}

	if (fMaxX != fMinX)
	{
		iMag = (int) (log(fMaxX - fMinX) / log(10.0));
		fStep = (double) pow(10.0, (double) iMag);

		iNumLines = (int) ((fMaxX -fMinX) / fStep);

		while (iNumLines < 5)
		{
			fStep = fStep / 2.0;
			iNumLines = (int) ((fMaxX-fMinX) / fStep);
		}
		fMinLine = (int)(((int)(fMinX/fStep)) * fStep);
		while (fMinLine <fMinX)
		{
			fMinLine+=fStep;
		}

		for (i = 0; i < iNumLines + 1; i++)
		{
			if (iGraphType == HTML_GRAPH_TYPE_BARS)
			{
				fX = OFFSET_X + (fMinLine + fStep * i - fMinX) / fRangeX * (GRAPH_WIDTH - fWidth);
			}
			else
			{
				fX = OFFSET_X + (fMinLine + fStep * i - fMinX) / fRangeX * GRAPH_WIDTH;
			}
			if (fX >= OFFSET_X && fX <= GRAPH_WIDTH + OFFSET_X){
				if (fabs(fStep * i +fMinLine) > 100000)
				{
					sValue = SG_Get_String(fStep * i +fMinLine);
				}
				else
				{
					sValue = SG_Get_String(fStep * i + fMinLine, 2, true);
				}
				SVG.Draw_Text(fX, GRAPH_HEIGHT + 10, sValue, 0, SG_T("Verdana"), 8, SG_T(""), SVG_ALIGNMENT_Center);
				SVG.Draw_Line(fX, GRAPH_HEIGHT, fX, GRAPH_HEIGHT - 5);
			}
		}
    }

	SVG.Draw_Line(OFFSET_X, 0, OFFSET_X, GRAPH_HEIGHT, 4);
	SVG.Draw_Line(OFFSET_X, GRAPH_HEIGHT, OFFSET_X + GRAPH_WIDTH, GRAPH_HEIGHT, 4);

	SVG.Save(Filename);

	if (bIncludeTableData)
	{
		CSG_Doc_HTML HTMLDoc;
		HTMLDoc.Open(LNG("Data Table"));

		sTableFilename = Filename;
		sTableFilename.Append(SG_T(".htm"));

		m_sHTMLCode.Append(SG_T("<a href=\"file://"));
		m_sHTMLCode.Append(sTableFilename);
		m_sHTMLCode.Append(SG_T("\">"));
		m_sHTMLCode.Append(LNG("Data Table"));
		m_sHTMLCode.Append(SG_T("</a><br><br>\n"));

		HTMLDoc._AddBicolumTable(&Data);
		HTMLDoc.Save(sTableFilename);

	}


}//method

void CSG_Doc_HTML::_AddBicolumTable(CSG_Points *pData)
{

	int i;

    m_sHTMLCode.Append(SG_T("<table width=\"99%\" style=\"background-color:transparent;\" border=0 cellspacing=0 cellpadding=2 >\n"));
	m_sHTMLCode.Append(
		SG_T("<tr bgcolor=\"#CCCCCC\">\n")
		SG_T("<td width=\"50%\" align=\"center\">X</td><td width=\"50%\" align=\"center\">Y</td>\n")
		SG_T("</tr>\n")
	);

	for (i=0; i<pData->Get_Count(); i++)
	{
		m_sHTMLCode.Append(SG_T("<tr>\n"));
		m_sHTMLCode.Append(SG_T("<td width=\"50%\" align=\"center\">"));
		m_sHTMLCode.Append(SG_Get_String(pData->Get_X(i),2));
		m_sHTMLCode.Append(SG_T("</td>"));
		m_sHTMLCode.Append(SG_T("<td width=\"50%\" align=\"center\">"));
		m_sHTMLCode.Append(SG_Get_String(pData->Get_Y(i),2));
		m_sHTMLCode.Append(SG_T("</td>"));
		m_sHTMLCode.Append(SG_T("\n</tr>\n"));
	}

	m_sHTMLCode.Append(SG_T("\n</table>\n"));
	m_sHTMLCode.Append(SG_T("<p align=\"center\"><i>"));
	m_sHTMLCode.Append(LNG("Data Table"));
	m_sHTMLCode.Append(SG_T("</i></p>\n"));

}

void CSG_Doc_HTML::AddTable(const SG_Char ***Table,
								int iRows,
								int iCols,
								const SG_Char *Description)
{

	int i,j;
	int iWidth = (int) (100/iCols);

    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++)
	{
		if (i==0)
		{
			m_sHTMLCode.Append(SG_T("<tr bgcolor=\"#CCCCCC\">\n"));
		}
		else
		{
			m_sHTMLCode.Append(SG_T("<tr>\n"));
		}
		for (j=0; j<iCols; j++){
			m_sHTMLCode.Append(SG_T("<td width=\""));
			m_sHTMLCode.Append(SG_Get_String(iWidth,0));
			m_sHTMLCode.Append(SG_T("%\" align=\"center\">"));
			try
			{
				m_sHTMLCode.Append(Table[i][j]);
			}
			catch(...){}
			m_sHTMLCode.Append(SG_T("</td>"));
		}
		m_sHTMLCode.Append(SG_T("\n</tr>\n"));
	}

	m_sHTMLCode.Append(SG_T("\n</table>\n"));
	m_sHTMLCode.Append(SG_T("<p align=\"center\"><i>"));
	m_sHTMLCode.Append(Description);
	m_sHTMLCode.Append(SG_T("</i></p>\n"));

}

void CSG_Doc_HTML::AddTable(CSG_Table *pTable)
{

	int i,j;
	int iWidth = (int) (100/pTable->Get_Field_Count());

    m_sHTMLCode.Append(SG_T("<table width=\"99%\" style=\"background-color:transparent;\" border=0 cellspacing=0 cellpadding=2 >\n"));

	m_sHTMLCode.Append(SG_T("<tr bgcolor=\"#CCCCCC\">\n"));
	for (i=0; i<pTable->Get_Field_Count(); i++){
		m_sHTMLCode.Append(SG_T("<td width=\""));
		m_sHTMLCode.Append(SG_Get_String(iWidth,0));
		m_sHTMLCode.Append(SG_T("%\" align=\"center\">"));
		m_sHTMLCode.Append(pTable->Get_Field_Name(i));
		m_sHTMLCode.Append(SG_T("</td>"));
	}
	m_sHTMLCode.Append(SG_T("\n</tr>\n"));

	for (i=0; i<pTable->Get_Record_Count(); i++)
	{
		m_sHTMLCode.Append(SG_T("<tr>\n"));
		for (j=0; j<pTable->Get_Field_Count(); j++){
			m_sHTMLCode.Append(SG_T("<td width=\""));
			m_sHTMLCode.Append(SG_Get_String(iWidth,0));
			m_sHTMLCode.Append(SG_T("%\" align=\"center\">"));
			try
			{
				m_sHTMLCode.Append(pTable->Get_Record(i)->asString(j));
			}
			catch(...){}
			m_sHTMLCode.Append(SG_T("</td>"));
		}
		m_sHTMLCode.Append(SG_T("\n</tr>\n"));
	}

	m_sHTMLCode.Append(SG_T("\n</table>\n"));
	m_sHTMLCode.Append(SG_T("<p align=\"center\"><i>"));
	m_sHTMLCode.Append(pTable->Get_Name());
	m_sHTMLCode.Append(SG_T("</i></p>\n"));

}

bool CSG_Doc_HTML::_Draw_Shape(CSG_Doc_SVG &SVG, CSG_Shape *pShape, CSG_Rect GlobalRect, int Fill_Color, int Line_Color, int Line_Width, int Point_Width)
{
	if( pShape && pShape->is_Valid() )
	{
		int			iPart, iPoint;
		double		x,y;
		TSG_Point	Point;
		CSG_Points	Points;
		double		dWidth, dHeight;
		double		dOffsetX, dOffsetY;

		if (GlobalRect.Get_XRange() / GlobalRect.Get_YRange() > MAP_WIDTH / MAP_HEIGHT)
		{
			dWidth	= MAP_WIDTH * .95;
			dHeight	= MAP_HEIGHT / GlobalRect.Get_XRange() * GlobalRect.Get_YRange();
		}
		else{
			dHeight	= MAP_HEIGHT * .95;
			dWidth	= MAP_WIDTH / GlobalRect.Get_YRange() * GlobalRect.Get_XRange();
		}

		dOffsetX = (MAP_WIDTH  - dWidth)  / 2.;
		dOffsetY = (MAP_HEIGHT - dHeight) / 2.;

		SVG.Draw_Rectangle(0,0,MAP_WIDTH,MAP_HEIGHT,SG_COLOR_NONE,SG_COLOR_BLACK,1,SG_T("%"));

		for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
		{
			Points.Clear();

			for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
			{
				Point = pShape->Get_Point(iPoint, iPart);
				x = dOffsetX + (Point.x - GlobalRect.Get_XMin()) / GlobalRect.Get_XRange() * dWidth;
				y = (Point.y - GlobalRect.Get_YMin()) / GlobalRect.Get_YRange() * dHeight;
				y = MAP_HEIGHT - y - dOffsetY;
				Points.Add(x, y);
			}

			switch( pShape->Get_Type() )
			{
			case SHAPE_TYPE_Point:
			case SHAPE_TYPE_Points:
				for(iPoint=0; iPoint<Points.Get_Count(); iPoint++)
				{
					SVG.Draw_Circle(Points[iPoint].x, Points[iPoint].y, Point_Width, Fill_Color, Line_Color, Line_Width, SG_T("%"));
				}
				break;

			case SHAPE_TYPE_Line:
				SVG.Draw_Line(Points, Line_Width, SG_T(""), Line_Color);
				break;

			case SHAPE_TYPE_Polygon:
				if( ((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) )
				{
					SVG.Draw_Polygon(Points, SG_COLOR_WHITE, Line_Color, Line_Width, SG_T(""));
				}
				else
				{
					SVG.Draw_Polygon(Points, Fill_Color, Line_Color, Line_Width, SG_T(""));
				}
				break;
			}
		}

		return( true );
	}

	return( false );
}

bool CSG_Doc_HTML::Draw_Shapes(CSG_Shapes *pShapes, const SG_Char *Filename, int Fill_Color, int Line_Color, int Line_Width)
{

	CSG_Doc_SVG	SVG;
	CSG_Rect	r;

	if( pShapes && pShapes->is_Valid())
	{
		r = pShapes->Get_Extent();
		SVG.Open((int)MAP_WIDTH, (int)MAP_HEIGHT);

		for(int iShape=0; iShape<pShapes->Get_Count(); iShape++)
		{
			_Draw_Shape(SVG, pShapes->Get_Shape(iShape), r, Fill_Color, Line_Color, 1, 3);
		}

		SVG.Save(Filename);

		m_sHTMLCode.Append(SG_T("<center>\n<object type=\"image/svg+xml\" width=\""));
		m_sHTMLCode.Append(SG_Get_String(MAP_WIDTH, 0));
		m_sHTMLCode.Append(SG_T("\" height=\""));
		m_sHTMLCode.Append(SG_Get_String(MAP_HEIGHT, 0));
		m_sHTMLCode.Append(SG_T("\" data=\"file://"));
		m_sHTMLCode.Append(Filename);
		m_sHTMLCode.Append(SG_T("\"></object></center><br>\n"));

		return( true );

	}

	return( false );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -