Line style in EMF

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, 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
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Line style in EMF

Post by Yury »

Hello, we are using Core API SDK to generate the PDF with the embedded EMF file.
This way EMF is placed to PDF output using the code like this:

Code: Select all

HRESULT PDFXBuilder::PlaceMetafile(PageItem* pageItem,  HENHMETAFILE hMeta, const PXC::PXC_Rect& rc)
{
   HRESULT hr = S_OK;
  try
  {
   CComPtr<PXC::IPXC_XForm> pXForm;
   hr = m_pCoreDoc->ConvertMetafile((PXC::HANDLE_T)hMeta, 0, nullptr, &pXForm);
   if (FAILED(hr))
      return hr;
   return PlaceXForm(pageItem, pXForm, rc);
  }
  catch( ... )
  {
	  return -1;
  }   
}
This works. And I already contacted you about this. However this works only for 90%.
We have issue, which we really need to get rid of.
DASH and DOT styled lines are not displayed ( parsed ) properly.
I remember we discussed that GDI+ EMF format is hard to support. However, we switched to plain GDI to draw lines properly, but still have bad results.
I'm attaching the resulted PDF & EMF. Code, which draws the dash line looks as this:

Code: Select all

CPen pen;
		HPEN hPen = ::ExtCreatePen(PS_GEOMETRIC | m_pPen->GetDashStyle(), iLineWidth ,&lb, 0, NULL);
		BOOL bAttached = pen.Attach(hPen );
		//////////////////////////////////////////////////////////////

		CPen* pOldPen = pDC->SelectObject( &pen );

		for( UINT i = 0; i < m_vPoints.size(); i++ )
		{
			PointF pt = m_vPoints[i];
			_parent->ToStage( pt );
			GetLayer()->FromStage( pt );
			if(i == 0 )
				pDC->MoveTo( (int)(pt.X * fScale + 0.5), (int)(pt.Y * fScale + 0.5) );
				// pDC->MoveTo( std::ceil(  pt.X*fScale ), std::ceil( pt.Y*fScale ) );
			else
				pDC->LineTo( (int)(pt.X * fScale + 0.5), (int)(pt.Y * fScale + 0.5) );
				// pDC->LineTo(  std::ceil( pt.X*fScale ),std::ceil( pt.Y*fScale ) );
		}
		pDC->SelectObject(pOldPen);
		pGr->ReleaseHDC( hdc );
Any help?, update? workaround?
Regards,
Yury
Attachments
emf_output.jpg
342696.pdf
(78.15 KiB) Downloaded 152 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Line style in EMF

Post by Sasha - Tracker Dev Team »

Hello Yury,

Could you please provide the emf file that you were using for us to test?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Here you are
Attachments
img-2500.zip
(13.46 KiB) Downloaded 149 times
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Line style in EMF

Post by Ivan - Tracker Software »

I have modified a bit coefficients to use in dash-dot patterns. Now your converted EMF will looks like in attached file.
img-2500.pdf
(80.38 KiB) Downloaded 179 times
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Looks excellent. Can I get the new build?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Line style in EMF

Post by Sasha - Tracker Dev Team »

Hello Yury,

Of course, you can download it when it officially will be out ;)

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Alex, any time forecasts? The matter is that this bug is show stopper for our product. x64 edition.

Regards,
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17823
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Line style in EMF

Post by Tracker Supp-Stefan »

Hello Yury,

There is still no official release date for build 323, but I've asked Alex if we can prepare e.g. a "nightly" build with the fix included.
He has finished for the day - so the reply will be available tomorrow - but we will see what we can arrange for you!

Cheers,
Stefan
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17823
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Line style in EMF

Post by Tracker Supp-Stefan »

Hello Yury,

I've just spoken with Alex - and unfortunately we can't provide a 'nightly' build at this time - as the development version is not stable enough at the moment for such a release.
Also - given that you need to put this in your live product - we do not believe a nightly (and not properly tested) build will be good to include there.
So unfortunately - you will have to wait till the official release of build 323 to implement the fix at your end.

Regards,
Stefan
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Hi Stefan, thank you for the care about this.

I understand that not only this fix is included into the 323, and that's why you can't release or even share it prior proper testing. That's Ok.
However, isn't it possible to take the last stable release, include this patch, rebuild and give it us. As far as I understand, fix didn't influence on over parts of code.

Also, when is the 323 is expected ?

Regards,
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17823
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Line style in EMF

Post by Tracker Supp-Stefan »

Hi Yury,

I will need to check with Ivan who implemented the fix - but he is in our Canadian office.
So I will only be able to confirm whether or not we will be able to do this later in the European afternoon.

Regards,
Stefan
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Stefan, any update on this?

Regards,
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17823
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Line style in EMF

Post by Tracker Supp-Stefan »

Hi Yuri,

I did contact Ivan - but have not received a reply from him on this one yet - so going to speak with some of the other colleagues in the European office to see what we can do!

Regards,
Stefan
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17823
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Line style in EMF

Post by Tracker Supp-Stefan »

Hi Yury,

I've been told that we will prepare the needed file for you. A colleague from the European office has been tasked with this - so we will share it with you as soon as it's possible.

Regards,
Stefan
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Thanks, Stefan!
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Line style in EMF

Post by Sasha - Tracker Dev Team »

Hello Yury,

Here's the build:
http://docu-track.co.uk/devbuilds/19304/PDFXCoreAPI.zip

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Thank you very much!

I've inserted this into the code. Looks working!!! We continue testing and let you know if something.
The one found issue is:
If I create pen with this options:

Code: Select all

HPEN hPen = ::ExtCreatePen(PS_JOIN_ROUND | PS_ENDCAP_FLAT |  PS_GEOMETRIC | gdiPlusPen->GetDashStyle(), iLineWidth ,&lb, 0, NULL);
It works perfect. But if I use this

Code: Select all

HPEN hPen = ::ExtCreatePen( PS_GEOMETRIC | gdiPlusPen->GetDashStyle(), iLineWidth ,&lb, 0, NULL);
It produces strange long dashes....

However, this is not critical for us at the moment.


Best regards!
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Line style in EMF

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Line style in EMF

Post by Ivan - Tracker Software »

Can you provide us EMFs with both of these pens ?
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Hello, here is initial test result:
Archive contains 2 files: PDF & PowerPoint with the EMF, inserted.

Note, that as soon as the line thickness grows up, PDF output become different.
Lengths of the line elements ( dot, dash, space ) do not correspond to the line thickness. Could this be fixed?
The matter is that actual lengths of elements should be multiplied on line width (logical sizes). Your implementation seems use hardcoded lengths of elements.
Example:
you using array of elements like this:

Code: Select all

const DWORD dwDashSize	= 3;
const DWORD dwSpaceSize	= 2;
const DWORD dwDotSize	= 1;
DWORD dwDashDotStyle[5]		= {dwDashSize, dwSpaceSize, dwDotSize, dwSpaceSize};
But instead, it'd be as this:

Code: Select all

DWORD dwDashDotStyle[5]		= {dwDashSize * lineWidth, dwSpaceSize* lineWidth, dwDotSize* lineWidth, dwSpaceSize* lineWidth};
Any considerations?

Best regards,
Attachments
Standard-Styles.zip
(29.19 KiB) Downloaded 148 times
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Another case... If the we use custom line style ( PS_USERSTYLE ),
x64 & Win32 CoreAPI behaves differently. x64 version produces incorrect result. Win32 version works as expected.
Here is the code, used to output line:

Code: Select all

//#define PS_DASH             1       /* -------  */
//#define PS_DOT              2       /* .......  */
//#define PS_DASHDOT          3       /* _._._._  */
//#define PS_DASHDOTDOT       4       /* _.._.._  */

const DWORD dwDashSize	= 3;
const DWORD dwSpaceSize	= 1;
const DWORD dwDotSize	= 1;

DWORD dwDashStyle[5]		= {dwDashSize, dwSpaceSize, dwDashSize, dwSpaceSize, 0};
DWORD dwDotStyle[3]			= {dwDotSize, dwSpaceSize, 0};
DWORD dwDashDotStyle[5]		= {dwDashSize, dwSpaceSize, dwDotSize, dwSpaceSize, 0};
DWORD dwDashDotDotStyle[7]	= {dwDashSize, dwSpaceSize, dwDotSize, dwSpaceSize, dwDotSize, dwSpaceSize, 0};
DWORD* dwStyles[5] = {NULL, dwDashStyle, dwDotStyle, dwDashDotStyle, dwDashDotDotStyle};
DWORD getDwStyleCount( DWORD* pStyle )
{
	DWORD dwCount(0);
	if( pStyle == NULL )
		return dwCount;
	while( pStyle[dwCount] != 0)
		dwCount++;
	return dwCount;
}
DWORD* getLpStyle( DWORD style, DWORD dwLineWidth )
{
	DWORD* dwStyleIndex = dwStyles[style];
	DWORD count = getDwStyleCount( dwStyleIndex );
	DWORD* pdwStyle = new DWORD[ count ];
	for( int i = 0; i < count; i++ )
		pdwStyle[i] = dwStyleIndex[i] * dwLineWidth;
	return pdwStyle;
} 
//////////////////////////////////////////
//#define _TRACKER_FIX_TEST
/////////////////////////////////////////////////
void DrawHDCDottedLine(Graphics* pGr, Pen* gdiPlusPen, vector<PointF> vPointsTranslated )
{

    LOGBRUSH lb;
	Color penColor;
	gdiPlusPen->GetColor( &penColor );
	lb.lbStyle = BS_SOLID;	
	lb.lbColor = penColor.ToCOLORREF();
	lb.lbHatch = 0;
	
	Matrix m;
	pGr->GetTransform(&m);
	REAL Elements[ 6 ];
	m.GetElements( Elements );
	REAL fScale = Elements[0];

	HDC hdc( pGr->GetHDC() );
	CDC* pDC = CDC::FromHandle( hdc );

	int iLineWidth =  ( gdiPlusPen->GetWidth()* fScale ) <= 1 ?  1 : gdiPlusPen->GetWidth() * fScale;

	CPen pen;
	DWORD dwStyleCount = getDwStyleCount( dwStyles[gdiPlusPen->GetDashStyle()] );
	DWORD* lpStyle = getLpStyle( gdiPlusPen->GetDashStyle(),  iLineWidth );
#ifdef _TRACKER_FIX_TEST
	HPEN hPen = ::ExtCreatePen(PS_JOIN_ROUND | PS_ENDCAP_FLAT |  PS_GEOMETRIC | gdiPlusPen->GetDashStyle(), iLineWidth ,&lb, 0, NULL);
	pen.Attach(hPen );
#else
	HPEN hPen = ::ExtCreatePen(PS_JOIN_ROUND | PS_ENDCAP_FLAT | PS_USERSTYLE |  PS_GEOMETRIC | gdiPlusPen->GetDashStyle(), iLineWidth ,&lb, dwStyleCount, lpStyle);
	pen.Attach(hPen );
	delete lpStyle;
#endif
    CPen* pOldPen = pDC->SelectObject( &pen );
    for( UINT i = 0; i < vPointsTranslated.size(); i++ )
    {
        PointF pt = vPointsTranslated[i];
        if(i == 0 )
			pDC->MoveTo( (int)(pt.X * fScale + 0.5), (int)(pt.Y * fScale + 0.5) );
        else
			pDC->LineTo( (int)(pt.X * fScale + 0.5), (int)(pt.Y * fScale + 0.5) );
    }
    pDC->SelectObject(pOldPen);
    pGr->ReleaseHDC( hdc );
}
Attachments
user-style.zip
(58.35 KiB) Downloaded 129 times
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Hi, any updates on this?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17823
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Line style in EMF

Post by Tracker Supp-Stefan »

Hello Yury,

Ivan is currently working on a high priority task, and once he is done with it - he will look at your issue again.
So apologies for the delay and lack of updates - but we will have more for you shortly.

Regards,
Stefan
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Line style in EMF

Post by Ivan - Tracker Software »

I made some changes in handling dash patterns.
Please download updated DLL (64-bit only for now): http://www.docu-track.co.uk/nightbuild/ ... 2_6_rc.zip

If you have any comments, please let me know.

We are going to release build 322.6 next week, and these changes will be included in this build.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Line style in EMF

Post by Yury »

Hello, this is PDFXEdit, but we need PDFXCoreAPI.x64. Can I get it?

Regards
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Line style in EMF

Post by Ivan - Tracker Software »

Sorry, my fault.
proper DLL can be found here: http://www.docu-track.co.uk/nightbuild/ ... 2_6_rc.zip
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Post Reply