Tile pattern rotating

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
baranyviki
User
Posts: 7
Joined: Fri Feb 08, 2019 4:10 pm

Tile pattern rotating

Post 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
Attachments
Patterns.zip
(2.97 MiB) Downloaded 66 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Tile pattern rotating

Post 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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
baranyviki
User
Posts: 7
Joined: Fri Feb 08, 2019 4:10 pm

Re: Tile pattern rotating

Post 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
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Tile pattern rotating

Post by Sasha - Tracker Dev Team »

Hello Viki,

From what I see, there is no attached PNG.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
baranyviki
User
Posts: 7
Joined: Fri Feb 08, 2019 4:10 pm

Re: Tile pattern rotating

Post by baranyviki »

Hello Alex,

It's in the first post.

Regards,
Viki
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Tile pattern rotating

Post 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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply