예제 #1
0
  void MapPainterAgg::DrawLabel(const Projection& projection,
                                const MapParameter& parameter,
                                const LabelData& label)
  {
    if (dynamic_cast<const TextStyle*>(label.style.Get())!=NULL) {
      const TextStyle* style=dynamic_cast<const TextStyle*>(label.style.Get());
      double           r=style->GetTextColor().GetR();
      double           g=style->GetTextColor().GetG();
      double           b=style->GetTextColor().GetB();
      std::wstring     wideText(UTF8StringToWString(label.text));

      if (style->GetStyle()==TextStyle::normal) {

        SetFont(projection,
                parameter,
                label.fontSize);

        //renderer_bin->color(agg::rgba(r,g,b,a));
        renderer_aa->color(agg::rgba(r,g,b,label.alpha));

        DrawText(label.x,
                 label.y+fontEngine->ascender(),
                 wideText);
      }
      else if (style->GetStyle()==TextStyle::emphasize) {
        SetOutlineFont(projection,
                       parameter,
                       label.fontSize);

        //renderer_bin->color(agg::rgba(r,g,b,a));
        renderer_aa->color(agg::rgba(1,1,1,label.alpha));

        DrawOutlineText(label.x,
                        label.y+fontEngine->ascender(),
                        wideText,
                        2);

        SetFont(projection,
                parameter,
                label.fontSize);

        //renderer_bin->color(agg::rgba(r,g,b,a));
        renderer_aa->color(agg::rgba(r,g,b,label.alpha));

        DrawText(label.x,
                 label.y+fontEngine->ascender(),
                 wideText);
      }
    }
  }
예제 #2
0
void ETextBox::Draw() {
	if (_lpFont == NULL || _nFontSize<=0)
		return;
	EBox::Draw();

	if (_fTextHeight > 0 && _fTextWidth >= _fMinTextWidth) {
      _lpFont->setBlend(_fBlend);
      if (_textColor[0] >=0) {
         DrawOutlineText();
         _lpFont->setColor(_textColor[0], _textColor[1], _textColor[2], _textColor[3]); 
      }
      _lpFont->drawMultiline(_cText,_x+_marginLeft,_x+_w-_marginRight,_y+_marginUp,_nTextStyle,0,_nFontSize);
	}
}
void ProcessDateTime::UpdateTexture()
{
	Status stat;
	RectF layoutBox;
	SIZE textSize;

	RectF boundingBox(0.0f, 0.0f, 32.0f, 32.0f);

	UpdateCurrentText();

	if (bUpdateTexture)
	{
		bUpdateTexture = false;

		if (hFont)
		{
			DeleteObject(hFont);
			hFont = NULL;
		}

		hFont = GetFont();

		if (!hFont)
			return;
	}

	StringFormat format(Gdiplus::StringFormat::GenericTypographic());

	SetStringFormat(format);

	HDC hdc = CreateCompatibleDC(NULL);

	Font font(hdc, hFont);
	Graphics graphics(hdc);
	graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
	if (strCurrentText.IsValid())
	{

		stat = graphics.MeasureString(strCurrentText, -1, &font, PointF(0.0f, 0.0f), &format, &boundingBox);
		if (stat != Ok)
			Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Gdiplus::Graphics::MeasureString failed: %u", (int)stat);
		if (bUseOutline)
		{
			//Note: since there's no path widening in DrawOutlineText the padding is half than what it was supposed to be.
			boundingBox.Width += outlineSize;
			boundingBox.Height += outlineSize;
		}
	}

	DeleteDC(hdc);
	hdc = NULL;

	if (boundingBox.Height < size)
	{
		textSize.cy = size;
		boundingBox.Height = float(size);
	}
	else
		textSize.cy = LONG(boundingBox.Height + EPSILON);

	textSize.cx = LONG(boundingBox.Width + EPSILON);
	//textSize.cx &= 0xFFFFFFFE;
	//textSize.cy &= 0xFFFFFFFE;

	textSize.cx += textSize.cx % 2;
	textSize.cy += textSize.cy % 2;

	ClampVal(textSize.cx, 32, 8192);
	ClampVal(textSize.cy, 32, 8192);
	//----------------------------------------------------------------------
	// write image

	{
		HDC hTempDC = CreateCompatibleDC(NULL);

		BITMAPINFO bi;
		zero(&bi, sizeof(bi));

		void* lpBits;

		BITMAPINFOHEADER &bih = bi.bmiHeader;
		bih.biSize = sizeof(bih);
		bih.biBitCount = 32;
		bih.biWidth = textSize.cx;
		bih.biHeight = textSize.cy;
		bih.biPlanes = 1;

		HBITMAP hBitmap = CreateDIBSection(hTempDC, &bi, DIB_RGB_COLORS, &lpBits, NULL, 0);

		Bitmap      bmp(textSize.cx, textSize.cy, 4 * textSize.cx, PixelFormat32bppARGB, (BYTE*)lpBits);

		Graphics graphics(&bmp);

		SolidBrush  brush(Gdiplus::Color(GetAlphaVal(opacity) | (color & 0x00FFFFFF)));

		DWORD bkColor;

		
		bkColor = ((strCurrentText.IsValid()) ? GetAlphaVal(0) : GetAlphaVal(0));

		if (textSize.cx > boundingBox.Width || textSize.cy > boundingBox.Height)
		{
			stat = graphics.Clear(Gdiplus::Color(0x00000000));
			if (stat != Gdiplus::Ok)
				Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Graphics::Clear failed: %u", (int)stat);

			SolidBrush *bkBrush = new SolidBrush(Gdiplus::Color(bkColor));

			graphics.FillRectangle(bkBrush, boundingBox);

			delete bkBrush;
		}
		else
		{
			stat = graphics.Clear(Gdiplus::Color(bkColor));
			if (stat != Ok)
				Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Graphics::Clear failed: %u", (int)stat);
		}

		graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		graphics.SetCompositingMode(Gdiplus::CompositingModeSourceOver);
		graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);

		if (strCurrentText.IsValid())
		{
			if (bUseOutline)
			{
				boundingBox.Offset(outlineSize / 2, outlineSize / 2);

				FontFamily fontFamily;
				GraphicsPath path;

				font.GetFamily(&fontFamily);

				path.AddString(strCurrentText, -1, &fontFamily, font.GetStyle(), font.GetSize(), boundingBox, &format);

				DrawOutlineText(&graphics, font, path, format, &brush);
			}
			else
			{
				stat = graphics.DrawString(strCurrentText, -1, &font, boundingBox, &format, &brush);
				if (stat != Gdiplus::Ok)
					Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Graphics::DrawString failed: %u", (int)stat);
			}
		}

		//----------------------------------------------------------------------
		// upload texture

		if (textureSize.cx != textSize.cx || textureSize.cy != textSize.cy)
		{
			if (texture)
			{
				delete texture;
				texture = NULL;
			}

			mcpy(&textureSize, &textSize, sizeof(textureSize));
			texture = CreateTexture(textSize.cx, textSize.cy, GS_BGRA, lpBits, FALSE, FALSE);
		}
		else if (texture)
			SetImage(texture,lpBits, GS_IMAGEFORMAT_BGRA, 4 * textSize.cx);

		if (!texture)
		{
			Log::writeError(LOG_RTSPSERV,1,"TextSource::UpdateTexture: could not create texture");
			DeleteObject(hFont);
		}

		DeleteDC(hTempDC);
		DeleteObject(hBitmap);
	}
}