TextSymbol.cpp 19.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
#include "TextSymbol.h"
#include"clsCrSurf.h"
#include"clsXML.h"
#include"clsUtil.h"
#include"clsMalloc.h"
#include "clsJson.h"
#include "clsPtree.h"
#include <math.h>
namespace DmapCore_30
{
	TextSymbol::TextSymbol()
	{
		m_pCrExtents = new cairo_text_extents_t();
		m_sFont = "Sans";
		m_dXdis = 0;
		m_dYdis = 0;
		m_bBackGround = false;
		m_bGlowing = false;      //发光
		m_bShadow = false; // 阴影
		m_iAntialiasing = false;  //防走样
		m_iSlant = 0;         //斜体
		m_iWeight = 0;          //加粗
		m_iFontSize = 10;       //字体大小
		m_iFontColor = 0xff000000;        //字体颜色 默认黑色
		r_font = 0; g_font = 0; b_font = 0; a_font = 1;
		m_iBGColor = 0xffffff00;          //背景颜色,默认白色
		r_bg = 1; g_bg = 1; b_bg = 0; a_bg = 1;
		m_iGlowingColor = 0xffff3333;     //发光色  默认(1,0.2,0.2,1)(rgba);
		r_glowing = 1; g_glowing = 0.2; b_glowing = 0.2; a_glowing = 1;
		m_iShadowColor = 0xff0000ff;      //阴影色  默认蓝色
		r_shadow = 0; g_shadow = 0; b_shadow = 1; a_shadow = 1;
	}


	TextSymbol::~TextSymbol()
	{
		if (m_pCrExtents)
			delete m_pCrExtents;
	}
	bool TextSymbol::AddRef()
	{
		m_iN++;
		return true;
	}
	bool TextSymbol::Release()
	{
		m_iN--;
		if (m_iN < 0)
			return false;
		if (!m_iN)
			delete this;
		return true;
	}

	int TextSymbol::RendererType()
	{
		return dmapTextSymbol;
	}

	bool TextSymbol::DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag)
	{
		return true;
	}
	bool  TextSymbol::DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag)
	{
		return true;
	}

	bool TextSymbol::Parse(boost::property_tree::ptree &pt, AppendBuffer *f)
	{
		clsXML clsX(f, "TEXTSYMBOL");
		clsXML::XMLAttrParse(pt, f, &m_sFont, "font");
		clsXML::XMLAttrParse(pt, f, &m_iFontSize, "fontsize");
		clsXML::XMLAttrParseColor(pt, f, &m_iFontColor, "fontcolor", "fonttransparency");
		clsXML::XMLAttrParse(pt, f, &m_dXdis, "x_dis");
		clsXML::XMLAttrParse(pt, f, &m_dYdis, "y_dis");
		clsXML::ParseEnum("antialiasing", pt, f, &m_iAntialiasing, "antialias_default", "antialias_none", "antialias_gray", "antialias_subpixel", "antialias_fase", "antialias_good", "antialias_best", "true", "false");
		clsXML::ParseEnum("slant", pt, f, &m_iSlant, "normal", "italic", "oblique");
		clsXML::ParseEnum("weight", pt, f, &m_iWeight, "normal", "bold");

		clsXML::XMLAttrParse(pt, f, &m_bBackGround, "background");
		if (m_bBackGround)
			clsXML::XMLAttrParseColor(pt, f, &m_iBGColor, "bgcolor", "bgtransparency");
		clsXML::XMLAttrParse(pt, f, &m_bGlowing, "glowing");
		if (m_bGlowing)
			clsXML::XMLAttrParseColor(pt, f, &m_iGlowingColor, "glowingcolor", "glowingtransparency");
		clsXML::XMLAttrParse(pt, f, &m_bShadow, "shadow");
		if (m_bShadow)
			clsXML::XMLAttrParseColor(pt, f, &m_iShadowColor, "shadowcolor", "shadowtransparency");
		//if (pt)
		{
			this->SetFontColor(m_iFontColor);
			this->SetBGColor(m_iBGColor);
			this->SetShadowColor(m_iShadowColor);
			this->SetGlowingColor(m_iGlowingColor);
		}
		return true;
	}

	bool TextSymbol::ParsePtree( boost::property_tree::ptree &pt)
	{
		boost::property_tree::ptree ptRenderer;
		//sprintf(resultbuff, R"("TEXTSYMBOL":{"antialiasing":"antialias_default",)");
		clsPtree::PtreeAttrParse("font", ptRenderer, this->m_sFont);
		clsPtree::PtreeAttrParse("fontsize", ptRenderer, this->m_iFontSize);
		//
		clsPtree::PtreeAttrParseColor("fontcolor", "fonttransparency", ptRenderer, m_iFontColor);
		clsPtree::PtreeAttrParse("x_dis", ptRenderer, this->m_dXdis);
		clsPtree::PtreeAttrParse("y_dis", ptRenderer, this->m_dYdis);
		//clsPtree::ParseEnum("antialiasing", ptRenderer, m_iAntialiasing, "antialias_default", "antialias_none", "antialias_gray", "antialias_subpixel", "antialias_fase", "antialias_good", "antialias_best", "true", "false");
		clsPtree::ParseEnum("slant", ptRenderer, m_iSlant,"normal", "italic", "oblique");
		clsPtree::ParseEnum("weight", ptRenderer, m_iWeight, "normal", "bold");
		clsPtree::PtreeAttrParse("background", ptRenderer, m_bBackGround);
		if (m_bBackGround)
			clsPtree::PtreeAttrParseColor("bgcolor", "bgtransparency", ptRenderer, m_iBGColor);
		
		clsPtree::PtreeAttrParse("glowing", ptRenderer, m_bGlowing);
		if (m_bGlowing)
		 	clsPtree::PtreeAttrParseColor("glowingcolor", "glowingtransparency", ptRenderer, m_iGlowingColor);
		

		clsPtree::PtreeAttrParse("shadow", ptRenderer, m_bShadow);
		if (m_bShadow)
		 	clsPtree::PtreeAttrParseColor("shadowcolor", "shadowtransparency", ptRenderer, m_iShadowColor);

		pt.add_child("TEXTSYMBOL",ptRenderer);
		return true;
	}

   void  TextSymbol::ToJson(AppendBuffer *ab)
   {
	   char buff[300] = {0};
	   char resultbuff[5000] ={0};
		sprintf(resultbuff, R"("TEXTSYMBOL":{"antialiasing":"antialias_default",)");
		clsJson::JsonAttrParse("font", resultbuff, buff, this->m_sFont);
		clsJson::JsonAttrParse("fontsize", resultbuff, buff, this->m_iFontSize);
		clsJson::JsonAttrParseColor("fontcolor", "fonttransparency", resultbuff, buff, m_iFontColor);
		clsJson::JsonAttrParse("x_dis", resultbuff, buff, this->m_dXdis);
		clsJson::JsonAttrParse("y_dis", resultbuff, buff, this->m_dYdis);
		//clsJson::ParseEnum("antialiasing", resultbuff, buff, m_iAntialiasing, "antialias_default", "antialias_none", "antialias_gray", "antialias_subpixel", "antialias_fase", "antialias_good", "antialias_best", "true", "false");
		clsJson::ParseEnum("slant", resultbuff, buff, m_iSlant,"normal", "italic", "oblique");
		clsJson::ParseEnum("weight", resultbuff, buff, m_iWeight, "normal", "bold");
		clsJson::JsonAttrParse("background", resultbuff, buff, m_bBackGround);
		if (m_bBackGround)
			clsJson::JsonAttrParseColor("bgcolor", "bgtransparency", resultbuff, buff, m_iBGColor);
		
		clsJson::JsonAttrParse("glowing", resultbuff, buff, m_bGlowing);
		if (m_bGlowing)
		 	clsJson::JsonAttrParseColor("glowingcolor", "glowingtransparency", resultbuff, buff, m_iGlowingColor);
		

		clsJson::JsonAttrParse("shadow", resultbuff, buff, m_bShadow);
		if (m_bShadow)
		 	clsJson::JsonAttrParseColor("shadowcolor", "shadowtransparency", resultbuff, buff, m_iShadowColor);

		clsJson::JsonAttrEnd(resultbuff);
		ab->AppendString(resultbuff);
   }


	const char* TextSymbol::GetFont()
	{
		return m_sFont.c_str();
	}
	bool   TextSymbol::SetFont(const char* sFont)
	{
		m_sFont = sFont;
		return true;
	}
	double TextSymbol::GetXdis()
	{
		return m_dXdis;
	}
	bool   TextSymbol::SetXdis(double dXdis)
	{
		m_dXdis = dXdis;
		return true;
	}
	double TextSymbol::GetYdis()
	{
		return m_dYdis;
	}
	bool   TextSymbol::SetYdis(double dYdis)
	{
		m_dYdis = dYdis;
		return true;
	}

	bool   TextSymbol::GetBackGround()
	{
		return m_bBackGround;
	}
	bool   TextSymbol::SetBackGround(bool bBackGround)
	{
		m_bBackGround = bBackGround;
		return  true;
	}
	bool   TextSymbol::GetGlowing()
	{
		return m_bGlowing;
	}
	bool   TextSymbol::SetGlowing(bool bGlowing)
	{
		m_bGlowing = bGlowing;
		return true;
	}
	bool   TextSymbol::GetShadow()
	{
		return m_bShadow;
	}
	bool   TextSymbol::SetShadow(bool bShadow)
	{
		m_bShadow = bShadow;
		return true;
	}
	int    TextSymbol::GetAntialiasing()
	{
		return m_iAntialiasing;
	}
	bool   TextSymbol::SetAntialiasing(int iAntialiasing)
	{
		m_iAntialiasing = iAntialiasing;
		return true;
	}

	int    TextSymbol::GetFontSize()
	{
		return m_iFontSize;
	}
	bool   TextSymbol::SetFontSize(int iFontSize)
	{
		m_iFontSize = iFontSize;
		return true;
	}
	int   TextSymbol::GetSlant()
	{
		return m_iSlant;
	}
	bool   TextSymbol::SetSlant(int  iSlant)
	{
		m_iSlant = iSlant;
		return true;
	}
	int   TextSymbol::GetWeight()
	{
		return m_iWeight;
	}
	bool   TextSymbol::SetWeight(int iWeight)
	{
		m_iWeight = iWeight;
		return true;
	}
	unsigned int    TextSymbol::GetFontColor()
	{
		return m_iFontColor;
	}
	bool   TextSymbol::SetFontColor(unsigned int iColor)
	{
		m_iFontColor = iColor;
		clsUtil::ToCairoColor(iColor, r_font, g_font, b_font, a_font);
		return true;
	}
	unsigned int    TextSymbol::GetBGColor()
	{
		return m_iBGColor;
	}
	bool   TextSymbol::SetBGColor(unsigned int iColor)
	{
		m_iBGColor = iColor;
		clsUtil::ToCairoColor(iColor, r_bg, g_bg, b_bg, a_bg);
		return true;
	}
	unsigned int    TextSymbol::GetGlowingColor()
	{
		return m_iGlowingColor;
	}
	bool   TextSymbol::SetGlowingColor(unsigned int iColor)
	{
		m_iGlowingColor = iColor;
		clsUtil::ToCairoColor(iColor, r_glowing, g_glowing, b_glowing, a_glowing);
		return true;
	}
	unsigned int    TextSymbol::GetShadowColor()
	{
		return m_iShadowColor;
	}
	bool   TextSymbol::SetShadowColor(unsigned int iColor)
	{
		m_iShadowColor = iColor;
		clsUtil::ToCairoColor(iColor, r_shadow, g_shadow, b_shadow, a_shadow);
		return true;
	}


	bool TextSymbol::SetCairo(clsCrSurf* pClsCS)
	{
		cairo_t* cr = pClsCS->m_pCr;

		clsMalloc clsM;
		const char* utf8 = m_sFont.c_str();

		/*bool flag = clsUtil::ConvertEncGB18030_UTF8(ss, clsM);
		if (!flag)
			return false;

		char* utf8 = clsM.mem;*/
		cairo_select_font_face(cr, utf8, (cairo_font_slant_t)m_iSlant, (cairo_font_weight_t)m_iWeight);
		cairo_set_font_size(cr, m_iFontSize);

		return true;
	}


	bool TextSymbol::DrawAText(clsCrSurf* pClsCS, double x, double y, char* sUTF8)
	{
		x += m_dXdis;
		y += m_dYdis;
		cairo_t* cr = pClsCS->m_pCr;
		//cairo_font_options_set_antialias(cfo, CAIRO_ANTIALIAS_GRAY);
		cairo_text_extents(cr, sUTF8, m_pCrExtents);
		int iX = (int)x;                          int iY = (int)y;
		int iTextW = (int)(m_pCrExtents->x_advance);  int iTextH = (int)(m_pCrExtents->height);
		//int surf_w = pClsCS->m_iW;                int surf_h = pClsCS->m_iH;

		/*
		文字避让部分
		*/

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		int xFrom = iX / gridsize;
		int xTo = (iX + iTextW) / gridsize;
		int yTo = iY / gridsize;
		int yFrom = (iY - iTextH) / gridsize;

		char * pFlag = pClsCS->m_pFlag;
		int iFlagW = pClsCS->m_iFlagW;
		int iFlagH = pClsCS->m_iFlagH;
		/*if (xFrom < 0 || yFrom < 0 || xTo >= iFlagW || yTo >= iFlagH)
			return false;*/

		if (xTo < 0 || xFrom >= iFlagW || yFrom >= iFlagH || yTo < 0)return true;
		if (xFrom < 0)xFrom = 0;
		if (xTo >= iFlagW)xTo = iFlagW - 1;
		if (yFrom < 0)yFrom = 0;
		if (yTo >= iFlagH)yTo = iFlagH - 1;

		/*if (xTo < 0)xTo = 0;
		if (xFrom >= iFlagW)xFrom = iFlagW - 1;
		if (yTo < 0)yTo = 0;
		if (yFrom >= iFlagH)yFrom = iFlagH - 1;*/


		/*
		if (xFrom < 0)xFrom = 0;
		if (xTo > iFlagW) xTo = iFlagW;
		if (xFrom > xTo)
		{
		xFrom = xFrom;
		}
		if (yFrom < 0)yFrom = 0;
		if (yTo > iFlagH) yTo = iFlagH;
		*/

		char *pFlagThis = pFlag + yFrom*iFlagW;
		for (int i = yFrom; i <= yTo; i++, pFlagThis += iFlagW)
		{
			char *pFlagThisNow = pFlagThis + xFrom;
			for (int j = xFrom; j <= xTo; j++, pFlagThisNow++)
			{
				if (*pFlagThisNow)return false;
				//if (pFlag[iFlagW*i + j])	return false;
			}
		}
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


		/*
		如果有背景,绘制背景
		*/
		if (m_bBackGround)
		{
			cairo_new_path(cr);
			cairo_rectangle(cr, x, y - iTextH, iTextW, iTextH);
			cairo_set_source_rgba(cr, r_bg, g_bg, b_bg, a_bg);
			cairo_fill(cr);
		}

		/*
		绘制发光
		*/
		if (m_bGlowing)
		{
			int iGlowingSize = 2;
			cairo_set_source_rgba(cr, r_glowing, g_glowing, b_glowing, a_glowing);
			for (int i = -GlowingSize; i <= GlowingSize; i++)
			{
				for (int j = -GlowingSize; j <= GlowingSize; j++)
				{
					cairo_move_to(cr, x + i, y + j);
					cairo_show_text(cr, sUTF8);
				}
			}
		}

		/*
		绘制阴影
		*/
		if (m_bShadow)
		{
			cairo_set_source_rgba(cr, r_shadow, g_shadow, b_shadow, a_shadow);
			if (m_bGlowing)
				cairo_move_to(cr, x + ShadowSize + GlowingSize, y + ShadowSize + GlowingSize);
			else
				cairo_move_to(cr, x + ShadowSize, y + ShadowSize);
			cairo_show_text(cr, sUTF8);
		}


		cairo_set_source_rgba(cr, r_font, g_font, b_font, a_font);
		cairo_move_to(cr, x, y); cairo_show_text(cr, sUTF8);


		/*
		标记避让
		*/
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		pFlagThis = pFlag + yFrom*iFlagW;
		for (int i = yFrom; i <= yTo; i++, pFlagThis += iFlagW)
		{
			memset(pFlagThis + xFrom, 1, (xTo - xFrom + 1));
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		return true;
	}


	bool TextSymbol::DrawAText(clsCrSurf* pClsCS, double x, double y, char* sUTF8, int xp, int yp)
	{
		x += m_dXdis*xp;
		y += m_dYdis*yp;
		cairo_t* cr = pClsCS->m_pCr;

		cairo_text_extents(cr, sUTF8, m_pCrExtents);
		int iX = (int)x;                          int iY = (int)y;
		int iTextW = (int)(m_pCrExtents->x_advance);  int iTextH = (int)(m_pCrExtents->height);
		//int surf_w = pClsCS->m_iW;                int surf_h = pClsCS->m_iH;

		/*
		文字避让部分
		*/

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		int xFrom = iX / gridsize;
		int xTo = (iX + iTextW) / gridsize;
		int yTo = iY / gridsize;
		int yFrom = (iY - iTextH) / gridsize;

		char * pFlag = pClsCS->m_pFlag;
		int iFlagW = pClsCS->m_iFlagW;
		int iFlagH = pClsCS->m_iFlagH;
		/*if (xFrom < 0 || yFrom < 0 || xTo >= iFlagW || yTo >= iFlagH)
		return false;*/

		if (xTo < 0 || xFrom >= iFlagW || yFrom >= iFlagH || yTo < 0)return true;
		if (xFrom < 0)xFrom = 0;
		if (xTo >= iFlagW)xTo = iFlagW - 1;
		if (yFrom < 0)yFrom = 0;
		if (yTo >= iFlagH)yTo = iFlagH - 1;

		/*if (xTo < 0)xTo = 0;
		if (xFrom >= iFlagW)xFrom = iFlagW - 1;
		if (yTo < 0)yTo = 0;
		if (yFrom >= iFlagH)yFrom = iFlagH - 1;*/


		/*
		if (xFrom < 0)xFrom = 0;
		if (xTo > iFlagW) xTo = iFlagW;
		if (xFrom > xTo)
		{
		xFrom = xFrom;
		}
		if (yFrom < 0)yFrom = 0;
		if (yTo > iFlagH) yTo = iFlagH;
		*/

		char *pFlagThis = pFlag + yFrom*iFlagW;
		for (int i = yFrom; i <= yTo; i++, pFlagThis += iFlagW)
		{
			char *pFlagThisNow = pFlagThis + xFrom;
			for (int j = xFrom; j <= xTo; j++, pFlagThisNow++)
			{
				if (*pFlagThisNow)return false;
				//if (pFlag[iFlagW*i + j])	return false;
			}
		}
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


		/*
		如果有背景,绘制背景
		*/
		if (m_bBackGround)
		{
			cairo_new_path(cr);
			cairo_rectangle(cr, x, y - iTextH, iTextW, iTextH);
			cairo_set_source_rgba(cr, r_bg, g_bg, b_bg, a_bg);
			cairo_fill(cr);
		}

		/*
		绘制发光
		*/
		if (m_bGlowing)
		{
			int iGlowingSize = 2;
			cairo_set_source_rgba(cr, r_glowing, g_glowing, b_glowing, a_glowing);
			for (int i = -GlowingSize; i <= GlowingSize; i++)
			{
				for (int j = -GlowingSize; j <= GlowingSize; j++)
				{
					cairo_move_to(cr, x + i, y + j);
					cairo_show_text(cr, sUTF8);
				}
			}
		}

		/*
		绘制阴影
		*/
		if (m_bShadow)
		{
			cairo_set_source_rgba(cr, r_shadow, g_shadow, b_shadow, a_shadow);
			if (m_bGlowing)
				cairo_move_to(cr, x + ShadowSize + GlowingSize, y + ShadowSize + GlowingSize);
			else
				cairo_move_to(cr, x + ShadowSize, y + ShadowSize);
			cairo_show_text(cr, sUTF8);
		}


		cairo_set_source_rgba(cr, r_font, g_font, b_font, a_font);
		cairo_move_to(cr, x, y); cairo_show_text(cr, sUTF8);


		/*
		标记避让
		*/
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		pFlagThis = pFlag + yFrom*iFlagW;
		for (int i = yFrom; i <= yTo; i++, pFlagThis += iFlagW)
		{
			memset(pFlagThis + xFrom, 1, (xTo - xFrom + 1));
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		return true;
	}

	

	bool TextSymbol::DrawAText(clsCrSurf* pClsCS, double x, double y, char* sUTF8, double dAngle)
	{
		x += m_dXdis;
		y += m_dYdis;
		//顺时针
		if (dAngle == 0)
			return this->DrawAText(pClsCS, x, y, sUTF8);

		cairo_t* cr = pClsCS->m_pCr;
	
		cairo_text_extents(cr, sUTF8, m_pCrExtents);
		int iX = (int)x;                          int iY = (int)y;
		int iTextW = (int)(m_pCrExtents->x_advance);  int iTextH = (int)(m_pCrExtents->height);
		int surf_w = pClsCS->m_iW;                int surf_h = pClsCS->m_iH;



		/*
		检查文字避让
		*/
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/*
		假设对图片上任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:
		x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ;
		y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;
		*/
		int xFrom = iX / gridsize;
		int xTo = (iX + iTextW) / gridsize;
		int yTo = iY / gridsize;
		int yFrom = (iY - iTextH) / gridsize;

		char * pFlag = pClsCS->m_pFlag;
		int iFlagW = pClsCS->m_iFlagW;
		int iFlagH = pClsCS->m_iFlagH;

		if (xFrom < 0)xFrom = 0;
		if (xTo >= iFlagW) xTo = iFlagW - 1;
		if (yFrom < 0)yFrom = 0;
		if (yTo >= iFlagH) yTo = iFlagH - 1;

	
		//选择其实不对
		for (int i = yFrom; i <= yTo; i++)
		{
			for (int j = xFrom; j <= xTo; j++)
			{
				double x_this = j*gridsize;
				double y_this = i*gridsize;
				double x_this_ = (x_this - x)*std::cos(dAngle) - (y_this - y)*std::sin(dAngle) + x;
				double y_this_ = (x_this - x)*std::sin(dAngle) + (y_this - y)*std::cos(dAngle) + y;
				if (x_this_ == x_this_ && y_this_ == y_this_)
				{
					int iXThis = ((int)(x_this_)) / gridsize;
					int iYThis = ((int)(y_this_)) / gridsize;

					if (iYThis*iFlagW + iXThis<0 || pFlag[iYThis*iFlagW + iXThis])
						return false;
				}
				else
				{
					return true;
				}
			}
		}
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




		{
			/*
			如果有背景,绘制背景
			*/
			if (m_bBackGround)
			{
				cairo_new_path(cr);
				cairo_move_to(cr, x, y);
				cairo_rotate(cr, dAngle);
				//cairo_rectangle(cr, x, y - iTextH, iTextW, iTextH);

				{
					cairo_rel_line_to(cr, iTextW, 0);
					cairo_rel_line_to(cr, 0, -iTextH);
					cairo_rel_line_to(cr, -iTextW, 0);
					cairo_close_path(cr);
				}
				cairo_rotate(cr, -dAngle);
				cairo_set_source_rgba(cr, r_bg, g_bg, b_bg, a_bg);
				cairo_fill(cr);
			}

			/*
			绘制发光
			*/
			if (m_bGlowing)
			{
				int iGlowingSize = 2;
				cairo_set_source_rgba(cr, r_glowing, g_glowing, b_glowing, a_glowing);
				for (int i = -GlowingSize; i <= GlowingSize; i++)
				{
					for (int j = -GlowingSize; j <= GlowingSize; j++)
					{
						cairo_move_to(cr, x + i, y + j);
						cairo_rotate(cr, dAngle);
						cairo_show_text(cr, sUTF8);
						cairo_rotate(cr, -dAngle);
					}
				}
			}

			/*
			绘制阴影
			*/
			if (m_bShadow)
			{
				int iShadowSize = 2;
				cairo_set_source_rgba(cr, r_shadow, g_shadow, b_shadow, a_shadow);
				if (m_bGlowing)
					cairo_move_to(cr, x + ShadowSize + GlowingSize, y + ShadowSize + GlowingSize);
				else
					cairo_move_to(cr, x + ShadowSize, y + ShadowSize);
				cairo_rotate(cr, dAngle); cairo_show_text(cr, sUTF8); cairo_rotate(cr, -dAngle);
			}


			cairo_set_source_rgba(cr, r_font, g_font, b_font, a_font);
			cairo_move_to(cr, x, y);
			cairo_rotate(cr, dAngle);
			cairo_show_text(cr, sUTF8);
			cairo_rotate(cr, -dAngle);

			/*cairo_set_source_rgba(cr, 1, 0.2, 0.2, 1);
			cairo_set_line_width(cr, 1);
			cairo_move_to(cr, x, y);
			cairo_rotate(cr, dAngle);
			cairo_rel_line_to(cr, iTextW,0);
			cairo_rel_line_to(cr, 0, -iTextH);
			cairo_rel_line_to(cr, -iTextW, 0);
			cairo_close_path(cr);
			cairo_stroke(cr);
			cairo_rotate(cr, -dAngle);*/
		}

		/*
		处理文字避让
		*/
		for (int i = yFrom; i <= yTo; i++)
		{
			for (int j = xFrom; j <= xTo; j++)
			{
				double x_this = j*gridsize;
				double y_this = i*gridsize;
				double x_this_ = (x_this - x)*cos(dAngle) - (y_this - y)*sin(dAngle) + x;
				double y_this_ = (x_this - x)*sin(dAngle) + (y_this - y)*cos(dAngle) + y;
				int iXThis = ((int)(x_this_)) / gridsize;
				int iYThis = ((int)(y_this_)) / gridsize;

				pFlag[iYThis*iFlagW + iXThis] = 1;
			}
		}

		return true;
	}

	bool TextSymbol::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag)
	{
		
		return false;
	}

}