Exemplo n.º 1
0
bool PngOutlineText::DrawString(
	Gdiplus::Graphics* pGraphics, 
	Gdiplus::FontFamily* pFontFamily,
	Gdiplus::FontStyle fontStyle,
	int nfontSize,
	const wchar_t*pszText, 
	Gdiplus::Rect rtDraw, 
	Gdiplus::StringFormat* pStrFormat)
{
	if(!pGraphics) return false;

	if(m_bEnableShadow&&m_pBkgdBitmap&&m_pFontBodyShadow&&m_pShadowStrategy&&m_pShadowStrategyMask)
	{
		Gdiplus::Graphics* pGraphicsMask=NULL;
		Gdiplus::Bitmap* pBmpMask=NULL;
		Gdiplus::Graphics* pGraphicsDrawn=NULL;
		Gdiplus::Bitmap* pBmpDrawn=NULL;

		bool b = RenderTransShadowA( pGraphics, &pGraphicsMask, &pBmpMask, &pGraphicsDrawn, &pBmpDrawn);

		if(!b) return false;

		b = RenderFontShadow(
			pGraphicsDrawn,
			pGraphicsMask,
			pBmpDrawn,
			pBmpMask,
			pFontFamily,
			fontStyle,
			nfontSize,
			pszText, 
			Gdiplus::Rect(rtDraw.X+m_ptShadowOffset.X, rtDraw.Y+m_ptShadowOffset.Y,rtDraw.Width,rtDraw.Height),
			pStrFormat);

		if(!b) 
		{
			delete pGraphicsMask;
			delete pGraphicsDrawn;
			delete pBmpDrawn;
			return false;
		}

		b = RenderTransShadowB( pGraphics, pGraphicsMask, pBmpMask, pGraphicsDrawn, pBmpDrawn);

		delete pGraphicsMask;
		delete pGraphicsDrawn;
		delete pBmpDrawn;

		if(!b) return false;
	}

	if(m_pTextStrategy&&m_pTextStrategyMask)
	{
		Gdiplus::Graphics* pGraphicsPng = new Gdiplus::Graphics((Gdiplus::Image*)(m_pPngBitmap));

		pGraphicsPng->SetCompositingMode(pGraphics->GetCompositingMode());
		pGraphicsPng->SetCompositingQuality(pGraphics->GetCompositingQuality());
		pGraphicsPng->SetInterpolationMode(pGraphics->GetInterpolationMode());
		pGraphicsPng->SetSmoothingMode(pGraphics->GetSmoothingMode());
		pGraphicsPng->SetTextRenderingHint(pGraphics->GetTextRenderingHint());
		pGraphicsPng->SetPageUnit(pGraphics->GetPageUnit());
		pGraphicsPng->SetPageScale(pGraphics->GetPageScale());

		bool b = m_pTextStrategy->DrawString(
			pGraphicsPng, 
			pFontFamily,
			fontStyle,
			nfontSize,
			pszText, 
			rtDraw, 
			pStrFormat);

		delete pGraphicsPng;

		if(!b)
			return false;
	}

	//pGraphics->DrawImage(m_pPngBitmap,0,0,m_pPngBitmap->GetWidth(),m_pPngBitmap->GetHeight());

	return true;
}
Exemplo n.º 2
0
static Image *ReadEMFImage(const ImageInfo *image_info,
  ExceptionInfo *exception)
{
  Gdiplus::Bitmap
    *bitmap;

  Gdiplus::BitmapData
     bitmap_data;

  Gdiplus::GdiplusStartupInput
    startup_input;

  Gdiplus::Graphics
    *graphics;

  Gdiplus::Image
    *source;

  Gdiplus::Rect
    rect;

  GeometryInfo
    geometry_info;

  Image
    *image;

  MagickStatusType
    flags;

  register Quantum
    *q;

  register ssize_t
    x;

  ssize_t
    y;

  ULONG_PTR
    token;

  unsigned char
    *p;

  wchar_t
    fileName[MagickPathExtent];

  assert(image_info != (const ImageInfo *) NULL);
  assert(image_info->signature == MagickSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
      image_info->filename);
  assert(exception != (ExceptionInfo *) NULL);

  image=AcquireImage(image_info,exception);
  if (Gdiplus::GdiplusStartup(&token,&startup_input,NULL) != 
    Gdiplus::Status::Ok)
    ThrowReaderException(CoderError, "GdiplusStartupFailed");
  MultiByteToWideChar(CP_UTF8,0,image->filename,-1,fileName,MagickPathExtent);
  source=Gdiplus::Image::FromFile(fileName);
  if (source == (Gdiplus::Image *) NULL)
    {
      Gdiplus::GdiplusShutdown(token);
      ThrowReaderException(FileOpenError,"UnableToOpenFile");
    }

  image->resolution.x=source->GetHorizontalResolution();
  image->resolution.y=source->GetVerticalResolution();
  image->columns=(size_t) source->GetWidth();
  image->rows=(size_t) source->GetHeight();
  if (image_info->density != (char *) NULL)
    {
      flags=ParseGeometry(image_info->density,&geometry_info);
      image->resolution.x=geometry_info.rho;
      image->resolution.y=geometry_info.sigma;
      if ((flags & SigmaValue) == 0)
        image->resolution.y=image->resolution.x;
      if ((image->resolution.x > 0.0) && (image->resolution.y > 0.0))
        {
          image->columns=(size_t) floor((Gdiplus::REAL) source->GetWidth() /
            source->GetHorizontalResolution() * image->resolution.x + 0.5);
          image->rows=(size_t)floor((Gdiplus::REAL) source->GetHeight() /
            source->GetVerticalResolution() * image->resolution.y + 0.5);
        }
    }

  bitmap=new Gdiplus::Bitmap((INT) image->columns,(INT) image->rows,
    PixelFormat32bppARGB);
  graphics=Gdiplus::Graphics::FromImage(bitmap);
  graphics->SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
  graphics->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
  graphics->SetTextRenderingHint(Gdiplus::TextRenderingHintClearTypeGridFit);
  graphics->Clear(Gdiplus::Color((BYTE) ScaleQuantumToChar(
    image->background_color.alpha),(BYTE) ScaleQuantumToChar(
    image->background_color.red),(BYTE) ScaleQuantumToChar(
    image->background_color.green),(BYTE) ScaleQuantumToChar(
    image->background_color.blue)));
  graphics->DrawImage(source,0,0,(INT) image->columns,(INT) image->rows);
  delete graphics;
  delete source;

  rect=Gdiplus::Rect(0,0,(INT) image->columns,(INT) image->rows);
  if (bitmap->LockBits(&rect,Gdiplus::ImageLockModeRead,PixelFormat32bppARGB,
    &bitmap_data) != Gdiplus::Ok)
  {
    delete bitmap;
    Gdiplus::GdiplusShutdown(token);
    ThrowReaderException(FileOpenError,"UnableToReadImageData");
  }

  image->alpha_trait=BlendPixelTrait;
  for (y=0; y < (ssize_t) image->rows; y++)
  {
    p=(unsigned char *) bitmap_data.Scan0+(y*abs(bitmap_data.Stride));
    if (bitmap_data.Stride < 0)
      q=GetAuthenticPixels(image,0,image->rows-y-1,image->columns,1,exception);
    else
      q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
    if (q == (Quantum *) NULL)
      break;

    for (x=0; x < (ssize_t) image->columns; x++)
    {
      SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
      SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
      SetPixelRed(image,ScaleCharToQuantum(*p++),q);
      SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
      q+=GetPixelChannels(image);
    }

    if (SyncAuthenticPixels(image,exception) == MagickFalse)
      break;
  }

  bitmap->UnlockBits(&bitmap_data);
  delete bitmap;
  Gdiplus::GdiplusShutdown(token);
  return(image);
}
Exemplo n.º 3
0
bool PngOutlineText::RenderFontShadow(	
	Gdiplus::Graphics* pGraphicsDrawn, 
	Gdiplus::Graphics* pGraphicsMask,
	Gdiplus::Bitmap* pBitmapDrawn,
	Gdiplus::Bitmap* pBitmapMask,
	Gdiplus::FontFamily* pFontFamily,
	Gdiplus::FontStyle fontStyle,
	int nfontSize,
	const wchar_t*pszText, 
	Gdiplus::Rect rtDraw, 
	Gdiplus::StringFormat* pStrFormat)
{
	if(!pGraphicsDrawn||!pGraphicsMask||!pBitmapDrawn||!pBitmapMask) return false;

	Gdiplus::Bitmap* pBitmapShadowMask = 
		m_pPngBitmap->Clone(0, 0, m_pPngBitmap->GetWidth(), m_pPngBitmap->GetHeight(), PixelFormat32bppARGB);

	Gdiplus::Graphics* pGraphicsShadowMask = new Gdiplus::Graphics((Gdiplus::Image*)(pBitmapShadowMask));
	Gdiplus::SolidBrush brushBlack(Gdiplus::Color(0,0,0));
	pGraphicsShadowMask->FillRectangle(&brushBlack, 0, 0, m_pPngBitmap->GetWidth(), m_pPngBitmap->GetHeight() );

	pGraphicsShadowMask->SetCompositingMode(pGraphicsDrawn->GetCompositingMode());
	pGraphicsShadowMask->SetCompositingQuality(pGraphicsDrawn->GetCompositingQuality());
	pGraphicsShadowMask->SetInterpolationMode(pGraphicsDrawn->GetInterpolationMode());
	pGraphicsShadowMask->SetSmoothingMode(pGraphicsDrawn->GetSmoothingMode());
	pGraphicsShadowMask->SetTextRenderingHint(pGraphicsDrawn->GetTextRenderingHint());
	pGraphicsShadowMask->SetPageUnit(pGraphicsDrawn->GetPageUnit());
	pGraphicsShadowMask->SetPageScale(pGraphicsDrawn->GetPageScale());

	bool b = false;

	b = m_pFontBodyShadowMask->DrawString(
		pGraphicsMask, 
		pFontFamily,
		fontStyle,
		nfontSize,
		pszText, 
		rtDraw, 
		pStrFormat);

	if(!b) return false;

	b = m_pShadowStrategyMask->DrawString(		
		pGraphicsShadowMask, 
		pFontFamily,
		fontStyle,
		nfontSize,
		pszText, 
		rtDraw, 
		pStrFormat);

	if(!b) return false;

	b = m_pFontBodyShadow->DrawString(
		pGraphicsDrawn, 
		pFontFamily,
		fontStyle,
		nfontSize,
		pszText, 
		rtDraw, 
		pStrFormat);

	if(!b) return false;

	b = m_pShadowStrategy->DrawString(		
		pGraphicsDrawn, 
		pFontFamily,
		fontStyle,
		nfontSize,
		pszText, 
		rtDraw, 
		pStrFormat);

	if(!b) return false;

	UINT* pixelsDest = NULL;
	UINT* pixelsMask = NULL;
	UINT* pixelsShadowMask = NULL;

	using namespace Gdiplus;

	BitmapData bitmapDataDest;
	BitmapData bitmapDataMask;
	BitmapData bitmapDataShadowMask;
	Rect rect(0, 0, m_pBkgdBitmap->GetWidth(), m_pBkgdBitmap->GetHeight() );

	pBitmapDrawn->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataDest );

	pBitmapMask->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataMask );

	pBitmapShadowMask->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataShadowMask );

	pixelsDest = (UINT*)bitmapDataDest.Scan0;
	pixelsMask = (UINT*)bitmapDataMask.Scan0;
	pixelsShadowMask = (UINT*)bitmapDataShadowMask.Scan0;

	if( !pixelsDest || !pixelsMask || !pixelsShadowMask )
		return false;

	UINT col = 0;
	int stride = bitmapDataDest.Stride >> 2;
	for(UINT row = 0; row < bitmapDataDest.Height; ++row)
	{
		for(col = 0; col < bitmapDataDest.Width; ++col)
		{
			using namespace Gdiplus;
			UINT index = row * stride + col;
			BYTE nAlpha = pixelsMask[index] & 0xff;
			BYTE nAlphaShadow = pixelsShadowMask[index] & 0xff;
			if(nAlpha>0&&nAlpha>nAlphaShadow)
			{
				pixelsDest[index] = nAlpha << 24 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
			}
			else if(nAlphaShadow>0)
			{
				pixelsDest[index] = nAlphaShadow << 24 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
				pixelsMask[index] = pixelsShadowMask[index];
			}
		}
	}

	pBitmapShadowMask->UnlockBits(&bitmapDataShadowMask);
	pBitmapMask->UnlockBits(&bitmapDataMask);
	pBitmapDrawn->UnlockBits(&bitmapDataDest);

	if(pGraphicsShadowMask)
	{
		delete pGraphicsShadowMask;
		pGraphicsShadowMask = NULL;
	}

	if(pBitmapShadowMask)
	{
		delete pBitmapShadowMask;
		pBitmapShadowMask = NULL;
	}

	return true;
}
void CTabsControl::DrawItem(CTabControl *item, Gdiplus::Graphics &g)
{
	CRect rect = ItemRect(item);

	g.ResetTransform();
	g.TranslateTransform((REAL)rect.left, (REAL)rect.top);

	RectF rf(0.0f, 0.0f, (REAL)rect.Width(), (REAL)rect.Height());
	RectF rx;

	if(item->selected)
	{
		#define shadowb 10

		CDIB tmp;
		tmp.Resize(rect.Width() + shadowb * 2, rect.Height() + shadowb * 2);
		if(tmp.Ready())
		{
			Graphics gt(tmp.bmp);
			RectF rx(0, 0, (REAL)tmp.Width(), (REAL)tmp.Height());
			
			GraphicsPath *path = new GraphicsPath();
			path->AddLine(rx.X + shadowb, rx.Y + rx.Height - shadowb, rx.X + rx.Width - 2 - shadowb, rx.Y + rx.Height - shadowb);
			path->AddLine(rx.X + rx.Width - 2 - shadowb, rx.Y + rx.Height - shadowb, rx.X + rx.Width - 2, rx.Y);
			path->AddLine(rx.X + rx.Width - 2, rx.Y, rx.X + rx.Width, rx.Y + rx.Height);
			path->AddLine(rx.X + rx.Width, rx.Y + rx.Height, rx.X, rx.Y + rx.Height);
			path->AddLine(rx.X, rx.Y, rx.X + shadowb, rx.Y + rx.Height - shadowb);
			path->CloseFigure();

			SolidBrush brush(0xff000000);
			gt.FillPath(&brush, path);

			tmp.Blur(tmp.Rect(), CRect(0, 0, 0, 0), shadowb);

			g.DrawImage(tmp.bmp, rf, shadowb, shadowb, rf.Width, rf.Height, UnitPixel);

			delete path;
		}
	}

	Font font(L"Arial", item->selected ? 8.0f : 8.0f);
	StringFormat *stringFormat = new StringFormat();
	stringFormat->SetAlignment(StringAlignmentCenter);
	stringFormat->SetLineAlignment(StringAlignmentCenter);
	stringFormat->SetTrimming(StringTrimmingEllipsisCharacter);
	stringFormat->SetFormatFlags(StringFormatFlagsLineLimit);

	if(item->icon->Ready())
	{
		g.SetInterpolationMode(InterpolationModeBicubic);
		rx = rf;
		rx.Y += 6;
		rx.Height -= (20 + rx.Y);
		rx.Width = rx.Height;
		rx.X += (rf.Width - rx.Width) / 2;

		if(item->selected)
		{
			rx.Y++;

			#define shadow 5
			CDIB tmp;
			tmp.Resize(item->icon->Width(), item->icon->Height());
			if(tmp.Ready())
			{
				tmp.Draw(CRect(shadow, shadow, 
					item->icon->Width() - shadow, 
					item->icon->Height() - shadow), 
					item->icon->Rect(), item->icon);
				DIB_ARGB *p = tmp.scan0;
				int size = tmp.Width() * tmp.Height();
				for(int i = 0; i < size; i++, p++)
				{
					p->r = 0;
					p->g = 0;
					p->b = 0;
				}
				tmp.Blur(tmp.Rect(), CRect(0, 0, 0, 0), shadow);
				g.DrawImage(tmp.bmp, RectF(rx.X, rx.Y + shadow, rx.Width, rx.Height));
			}
			tmp.Assign(item->icon);
			/*if(tmp.Ready())
			{
				DIB_ARGB *p = tmp.scan0;
				int size = tmp.Width() * tmp.Height();
				for(int i = 0; i < size; i++, p++)
				{
					p->r = 0x6f;
					p->g = 0xa6;
					p->b = 0xde;
				} 
			}*/
			g.DrawImage(tmp.bmp, rx);
		}
		else
		{
			g.DrawImage(item->icon->bmp, rx);
		}
	}

	SolidBrush brush(0xff000000);
	rx = rf;
	rx.Height = 20;
	rx.Y = rf.Height - rx.Height;

	rx.Y++;
	g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rx, stringFormat, &brush);

	brush.SetColor(item->selected && false ? 0xff6fa6de : 0xfff0f0f0);
	rx.Y--;
	g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rx, stringFormat, &brush);

	delete stringFormat;

	//POSITION p = items.Find(item);
	//items.GetNext(p);
	//if(p)
	{
		RectF rx = rf;
		rx.X += rx.Width - 1;
		rx.Width = 1;
		LinearGradientBrush brush(rx, Color(140, 0x69, 0x69, 0x69), Color(0x69, 0x69, 0x69), LinearGradientModeVertical);
		g.FillRectangle(&brush, rx);
	}
}