https://bugs.freedesktop.org/show_bug.cgi?id=46058
Bug #: 46058
Summary: Metafile drawing/conversion code fails to properly
adjust clipping rectangles when coordinate
transformations are set
Classification: Unclassified
Product: LibreOffice
Version: LibO 3.4.0 release
Platform: Other
OS/Version: All
Status: NEW
Severity: normal
Priority: medium
Component: Presentation
AssignedTo: [email protected]
ReportedBy: [email protected]
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();
}
--
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs