Bug 46058 - Metafile drawing/conversion code fails to properly adjust clipping rectangles when coordinate transformations are set
Summary: Metafile drawing/conversion code fails to properly adjust clipping rectangles...
Status: RESOLVED INVALID
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Impress (show other bugs)
Version:
(earliest affected)
3.4.0 release
Hardware: Other All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-14 11:29 UTC by Dotan Cohen
Modified: 2021-02-11 08:14 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dotan Cohen 2012-02-14 11:29:45 UTC
The following C++ code places an enhanced metafile onto the clipboard, which can then be pasted into powerpoint, wordpad, paint, LO impress, etc. The LO internal drawing functions seem to skip some of the metafile records or misinterpret them resulting in image corruption, the other aforementioned applications handle it correctly.

void DrawMetafile(HWND hWnd)
{
	HDC RefDC;
	RefDC = ::GetDC(hWnd);
	RECT TrueSize = {0, 0, 256, 256};//{100, 100, 356, 356};
	int iWidthMM	=	::GetDeviceCaps(RefDC, HORZSIZE); 
	int iHeightMM	=	::GetDeviceCaps(RefDC, VERTSIZE); 
	int iWidthPels	=	::GetDeviceCaps(RefDC, HORZRES); 
	int iHeightPels	=	::GetDeviceCaps(RefDC, VERTRES); 


	RECT MetaSize;
	MetaSize.left		=	::MulDiv(TrueSize.left, iWidthMM * 100 * 96, iWidthPels * 96);
	MetaSize.top		=	::MulDiv(TrueSize.top, iHeightMM * 100 * 96, iHeightPels * 96);
	MetaSize.right		=	::MulDiv(TrueSize.right, iWidthMM * 100* 96, iWidthPels * 96);
	MetaSize.bottom		=	::MulDiv(TrueSize.bottom, iHeightMM * 100* 96, iHeightPels * 96);

	HDC MetaDC = ::CreateEnhMetaFile(RefDC, NULL, &MetaSize, TEXT("Bug Demo."));

	::ReleaseDC(hWnd, RefDC);

	::FillRect(MetaDC, &TrueSize, ::GetSysColorBrush(COLOR_WINDOW));

	HBRUSH Black = ::CreateSolidBrush(0x00000000);
	HBRUSH Red = ::CreateSolidBrush(0x000000FF);
	HBRUSH Green = ::CreateSolidBrush(0x0000FF00);
	HBRUSH Blue = ::CreateSolidBrush(0x00FF0000);


	RECT SubRc = {16, 16, 48, 48};

	//	Fill everything with red, excluse a small rect, then fill everything with black
	//	Should leave a small red rectangle...
	::FillRect(MetaDC, &SubRc, Red);
	//	Following clip code is ignored in libreoffice
	::ExcludeClipRect(MetaDC, SubRc.left, SubRc.top, SubRc.right, SubRc.bottom);
	::FillRect(MetaDC, &TrueSize, Black);

	::OffsetRect(&SubRc, 192, 0);

	//	Fill a small rectangle with blue, limit clipping to this small rect, and fill everything with green
	//	should leave a small green rectangle with everything else still black
	::FillRect(MetaDC, &SubRc, Blue);
	//	Following clip code leaves weird borders in libreoffice
	::IntersectClipRect(MetaDC, SubRc.left, SubRc.top, SubRc.right, SubRc.bottom);
	::FillRect(MetaDC, &TrueSize, Green);

	//	Limit clipping to bottom half of image for third bug
	//	Then we fill it with blue, set a transformation, modify and restore clip rectangle, and
	//	fill everything with green. Should leave a solid green rectangle, but apparently
	//	world transformation does not update the selected clipping rectangle in both directions
	HRGN Temp = ::CreateRectRgn(0, 128, 256, 256);
	::SelectClipRgn(MetaDC, Temp);
	::DeleteObject(Temp);

	::FillRect(MetaDC, &TrueSize, Blue);

	XFORM stX, oldstX;
	ZeroMemory(&stX,sizeof(stX));
	stX.eM11	=	0.25;
	stX.eM22	=	0.25;
	stX.eDy		=	128;
	
	BOOL HadXform	=	::GetWorldTransform(MetaDC, &oldstX);
	ModifyWorldTransform(MetaDC, &stX, MWT_LEFTMULTIPLY);

	HRGN OldClip = ::CreateRectRgn(0, 0, 1, 1);
	::GetClipRgn(MetaDC, OldClip);
	//	Setting the clip region we just retrieved leads to a different clip region being selected...
	::SelectClipRgn(MetaDC, OldClip);
	::DeleteObject(OldClip);
	
	if (HadXform)
		::SetWorldTransform(MetaDC, &oldstX);
	else
	{
		XFORM DefXForm = {0};
		DefXForm.eM11 = DefXForm.eM22 = 1.0;
		::SetWorldTransform(MetaDC, &DefXForm);
	}

	::FillRect(MetaDC, &TrueSize, Green);


	::DeleteObject(Black);
	::DeleteObject(Red);
	::DeleteObject(Green);
	::DeleteObject(Blue);

	HENHMETAFILE MetaFile = ::CloseEnhMetaFile(MetaDC);
	ENHMETAHEADER Header = {EMR_HEADER, sizeof(ENHMETAHEADER)};
	::GetEnhMetaFileHeader(MetaFile, sizeof(ENHMETAHEADER), &Header);
	::OpenClipboard(hWnd);
	::EmptyClipboard();
	::SetClipboardData(CF_ENHMETAFILE, MetaFile);
	::CloseClipboard();
}
Comment 1 A (Andy) 2013-04-27 07:53:59 UTC
@Thorsten: Could you take a look at it?  Is this maybe something for you?
Comment 2 Thorsten Behrens (allotropia) 2013-04-29 10:54:28 UTC
(In reply to comment #0)
> The following C++ code places an enhanced metafile onto the
> clipboard...
>
Can you quickly attach the EMF, easier for me than getting your code
to run here? ;)
Comment 3 QA Administrators 2015-03-04 02:18:16 UTC
** Please read this message in its entirety before responding **

To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year.

There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present.

If you have time, please do the following:

Test to see if the bug is still present on a currently supported version of LibreOffice (4.4.1.2 or later): https://www.libreoffice.org/download/

If the bug is present, please leave a comment that includes the version of LibreOffice and your operating system, and any changes you see in the bug behavior

If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a short comment that includes your version of LibreOffice and Operating System

Please DO NOT

Update the version field
Reply via email (please reply directly on the bug tracker)
Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not appropriate in this case)

Thank you for your help!

-- The LibreOffice QA Team
This NEW Message was generated on: 2015-03-03
Comment 4 Jean-Baptiste Faure 2015-03-09 05:33:14 UTC
No answer from reporter since 2 years --> closing as INVALID
@reporter: Please, feel free to reopen if you are willing to answer the question in comment #2 (attach the EMF file).

Best regards. JBF
Comment 5 Prestonawrence 2020-05-12 06:20:53 UTC Comment hidden (spam)
Comment 6 romandavis 2021-02-11 08:14:50 UTC Comment hidden (spam)