Page 1 of 1

Tile pattern rotating

Posted: Fri Feb 08, 2019 4:30 pm
by baranyviki
Hi,

I'm trying to create a tile pattern from an image. The image is rotated in a certain angle. When I create the pattern with the function called "CreateTilePattern" I provide a BoundingBox in its first parameter. How should I define this box if I want it to be rotated like the image? I tried a few things but nothing worked so far. The result is always the same as the image in the pdf I provided in the zip file. I added a picture (wanted.jpg) too that shows what I want to achieve.

Thanks,
Viki

Re: Tile pattern rotating

Posted: Sat Feb 09, 2019 7:34 am
by Sasha - Tracker Dev Team
Hello Viki,

There is a sample on this matter. Download the CoreAPIDemo application available from here:
https://github.com/tracker-software/PDFCoreSDKExamples
There, you can see the sample "4.7. Patterns" - it has exactly what you need.

Cheers,
Alex

Re: Tile pattern rotating

Posted: Mon Feb 18, 2019 3:52 pm
by baranyviki
Hi Alex!
Sorry for the delayed reply. I tried to figure out my problem with the help of the sample project. Unfortunately I failed to find a solution to rotate an image pattern with a certain angle (e.g. 30°). The attached png shows, what I'd like to achieve. Maybe it's something trivial, but in the documentation, I cannot find anything about this. The attached pdf shows the following code's output, the nearest I've gotten to the solution. As I see it, my problem is that the picture is rotated, but the pattern's bounding box is always standing. Is there a way to rotate the bounding box? I hope you can help me with this.

In our c++ project, the createImagePattern method looks like this:

Code: Select all

HRESULT XChangePdfWriter::CreateImagePattern(HBITMAP& bmp, CComPtr<PXV::IPXC_Pattern>& pPattern, float bmpMaterialSizeX, float bmpMaterialSizeY, float dir, box& polyLineBbox_, BxPosTypes& type_)
{
	HRESULT hr = S_OK;

	PXV::PXC_Rect _boundingBox;
	METPT pt = GetBoundingBoxLeftBottomSize(polyLineBbox_, type_);

	_boundingBox.left = pt.x;
	_boundingBox.bottom = pt.y;
	_boundingBox.right = _boundingBox.left + bmpMaterialSizeX;
	_boundingBox.top = _boundingBox.bottom + bmpMaterialSizeY;


	CComPtr<PXV::IIXC_Page> page;
	hr = xPdf->m_imgCore->Page_CreateFromHBITMAP((PXV::HANDLE_T)bmp, 0, &page);
	if (FAILED(hr))
		return hr;

	page->FreeRotate(dir, RGB(255, 255, 255), PXV::IXC_FreeRotate::FreeRotate_Antialiasing, PXV::Color_UseAlpha);
	CComPtr<PXV::IPXC_Image> pImg;
	hr = xPdf->m_pDoc->AddImageFromIXCPage(page, 0, &pImg);
	if (FAILED(hr))
		return hr;
	CComPtr<PXV::IPXC_ContentCreator> pCC;
	hr = xPdf->m_pDoc->CreateContentCreator(&pCC);
	if (FAILED(hr))
		return hr;

	pCC->SaveState();
	pCC->TranslateCS(_boundingBox.left, _boundingBox.bottom);
	pCC->ScaleCS(bmpMaterialSizeX, bmpMaterialSizeY);
	pCC->PlaceImage(pImg);
	pCC->RestoreState();
	hr = xPdf->m_pDoc->CreateTilePattern(&_boundingBox, &pPattern);
	if (FAILED(hr))
		return hr;

	CComPtr<PXV::IPXC_Content> pC;
	pCC->Detach(&pC);
	pC->put_BBox(&_boundingBox);	
	pPattern->SetContent(pC, PXV::PlaceContent_Replace);
	
	if (FAILED(hr))
		pPattern = nullptr;
	return hr;
}
CComPtr<PXV::IPXC_Pattern> pPattern = nullptr;
hr = xPdf->CreateImagePattern(bmpBrush, pPattern, bmpSizeX*PdfXdpmm, bmpSizeY*PdfYdpmm, dir, polyLineBoundingBox, type);
xPdf->m_pContentCreator->SetPatternRGB(pPattern, VARIANT_TRUE, RGB(255, 255, 255));
hr = xPdf->m_pContentCreator->FillPath(VARIANT_TRUE, VARIANT_FALSE, XV::PXC_FillRule::FillRule_EvenOdd);
Thanks,
Viki

Re: Tile pattern rotating

Posted: Wed Feb 20, 2019 8:39 am
by Sasha - Tracker Dev Team
Hello Viki,

From what I see, there is no attached PNG.

Cheers,
Alex

Re: Tile pattern rotating

Posted: Wed Feb 20, 2019 8:45 am
by baranyviki
Hello Alex,

It's in the first post.

Regards,
Viki

Re: Tile pattern rotating

Posted: Thu Feb 21, 2019 3:17 pm
by Sasha - Tracker Dev Team
Hello Viki,

Just browsed through the code, sadly, there is no way to set a matrix for a pattern when creating it. The only way to achieve this is to create a normal pattern, do a SaveState for the content creator, then change the CTM of the content creator so that the pattern would rotate to the needed angle, draw the needed shape, do the fill and then do the RestoreState for the Content Creator.

Cheers,
Alex