Printing advice

L

Lloyd Dupont

I'm trying to print some of my document.
The problem is, the rendering of the document is not done through GDI+ at all but through plain old GDI, and I need it like that as I am using Uniscribe to layout text.

Anyway, when printing the text is completely out of place, I wonder if it's due to incorrrect Dpi settings? (or something else?)
I will investigate that.....

Anyway if any of you had similar experience and could shed some light?
Here is how I initialize my HDC (Managed C++):
====================
struct HDCInfo
{
HDC hdc;
// to be restored
HGDIOBJ font0;
HGDIOBJ brush0;
HGDIOBJ pen0;
XFORM transform0;
};
void NText::ScriptAnalysis::GetHDC(Graphics^ g, struct HDCInfo& info)
{
array<float>^ matrix = g->Transform->Elements;
pin_ptr<float> p_transform = &matrix[0];

info.hdc = (HDC)(void*)g->GetHdc(true);
info.font0 = ::GetCurrentObject(info.hdc, OBJ_FONT);
info.brush0 = ::GetCurrentObject(info.hdc, OBJ_BRUSH);
info.pen0 = ::GetCurrentObject(info.hdc, OBJ_PEN);
::GetWorldTransform(info.hdc, &info.transform0);

::SetGraphicsMode(info.hdc, GM_ADVANCED);
::SetBkMode(info.hdc, TRANSPARENT);
::SetWorldTransform(info.hdc, (XFORM*) p_transform);
}
====================
 
L

Lloyd Dupont

All my text output looks like shrink.
I mean all the characters are correctly positioned compare to each other, but it just occupies the top left quadrant.

I'm trying to print some of my document.
The problem is, the rendering of the document is not done through GDI+ at all but through plain old GDI, and I need it like that as I am using Uniscribe to layout text.

Anyway, when printing the text is completely out of place, I wonder if it's due to incorrrect Dpi settings? (or something else?)
I will investigate that.....

Anyway if any of you had similar experience and could shed some light?
Here is how I initialize my HDC (Managed C++):
====================
struct HDCInfo
{
HDC hdc;
// to be restored
HGDIOBJ font0;
HGDIOBJ brush0;
HGDIOBJ pen0;
XFORM transform0;
};
void NText::ScriptAnalysis::GetHDC(Graphics^ g, struct HDCInfo& info)
{
array<float>^ matrix = g->Transform->Elements;
pin_ptr<float> p_transform = &matrix[0];

info.hdc = (HDC)(void*)g->GetHdc(true);
info.font0 = ::GetCurrentObject(info.hdc, OBJ_FONT);
info.brush0 = ::GetCurrentObject(info.hdc, OBJ_BRUSH);
info.pen0 = ::GetCurrentObject(info.hdc, OBJ_PEN);
::GetWorldTransform(info.hdc, &info.transform0);

::SetGraphicsMode(info.hdc, GM_ADVANCED);
::SetBkMode(info.hdc, TRANSPARENT);
::SetWorldTransform(info.hdc, (XFORM*) p_transform);
}
====================
 
L

Lloyd Dupont

The Preview doesn't display text all :-(
And the printing just shrinking it ?!?.....
I'm trying to print some of my document.
The problem is, the rendering of the document is not done through GDI+ at all but through plain old GDI, and I need it like that as I am using Uniscribe to layout text.

Anyway, when printing the text is completely out of place, I wonder if it's due to incorrrect Dpi settings? (or something else?)
I will investigate that.....

Anyway if any of you had similar experience and could shed some light?
Here is how I initialize my HDC (Managed C++):
====================
struct HDCInfo
{
HDC hdc;
// to be restored
HGDIOBJ font0;
HGDIOBJ brush0;
HGDIOBJ pen0;
XFORM transform0;
};
void NText::ScriptAnalysis::GetHDC(Graphics^ g, struct HDCInfo& info)
{
array<float>^ matrix = g->Transform->Elements;
pin_ptr<float> p_transform = &matrix[0];

info.hdc = (HDC)(void*)g->GetHdc(true);
info.font0 = ::GetCurrentObject(info.hdc, OBJ_FONT);
info.brush0 = ::GetCurrentObject(info.hdc, OBJ_BRUSH);
info.pen0 = ::GetCurrentObject(info.hdc, OBJ_PEN);
::GetWorldTransform(info.hdc, &info.transform0);

::SetGraphicsMode(info.hdc, GM_ADVANCED);
::SetBkMode(info.hdc, TRANSPARENT);
::SetWorldTransform(info.hdc, (XFORM*) p_transform);
}
====================
 
L

Lloyd Dupont

I tried to multiply my world transform matrix by thes factor:
static int TextPrintScale(HDC& hdc)
{
HDC screenDc = GetDC(NULL);
int screenDpi = GetDeviceCaps(screenDc, LOGPIXELSX);
ReleaseDC(NULL, screenDc);
int devDpi = GetDeviceCaps(hdc, LOGPIXELSX);
return devDpi / screenDpi;
}

the weird thing is, it work well if I use this integer division of devDpi / screenDpi.
But first I tryed to used a float factor by returning:
return ((float) devDpi) / screenDpi;

And this was clearly wrong, (the page was clearly scaled too much as if 3 was right but 300.0 / 96.0 was not).
I'm kind of confused about that, I would have expect the float division to be right.
Any thoughts?

Also whatever I do the System.Windows.Forms.PrintPreviewDialog still display no text at all.... :-/



I'm trying to print some of my document.
The problem is, the rendering of the document is not done through GDI+ at all but through plain old GDI, and I need it like that as I am using Uniscribe to layout text.

Anyway, when printing the text is completely out of place, I wonder if it's due to incorrrect Dpi settings? (or something else?)
I will investigate that.....

Anyway if any of you had similar experience and could shed some light?
Here is how I initialize my HDC (Managed C++):
====================
struct HDCInfo
{
HDC hdc;
// to be restored
HGDIOBJ font0;
HGDIOBJ brush0;
HGDIOBJ pen0;
XFORM transform0;
};
void NText::ScriptAnalysis::GetHDC(Graphics^ g, struct HDCInfo& info)
{
array<float>^ matrix = g->Transform->Elements;
pin_ptr<float> p_transform = &matrix[0];

info.hdc = (HDC)(void*)g->GetHdc(true);
info.font0 = ::GetCurrentObject(info.hdc, OBJ_FONT);
info.brush0 = ::GetCurrentObject(info.hdc, OBJ_BRUSH);
info.pen0 = ::GetCurrentObject(info.hdc, OBJ_PEN);
::GetWorldTransform(info.hdc, &info.transform0);

::SetGraphicsMode(info.hdc, GM_ADVANCED);
::SetBkMode(info.hdc, TRANSPARENT);
::SetWorldTransform(info.hdc, (XFORM*) p_transform);
}
====================
 
J

Jason Newell

Lloyd,

You might try cc'ing the folks in
microsoft.public.dotnet.framework.drawing. They may be able to help you.

Jason
 
L

Lloyd Dupont

good idea Jason, thanks! ;-)

Jason Newell said:
Lloyd,

You might try cc'ing the folks in
microsoft.public.dotnet.framework.drawing. They may be able to help you.

Jason

Lloyd said:
I tried to multiply my world transform matrix by thes factor:
static int TextPrintScale(HDC& hdc)
{
HDC screenDc = GetDC(NULL);
int screenDpi = GetDeviceCaps(screenDc, LOGPIXELSX);
ReleaseDC(NULL, screenDc);
int devDpi = GetDeviceCaps(hdc, LOGPIXELSX);
return devDpi / screenDpi;
}

the weird thing is, it work well if I use this integer division of devDpi
/ screenDpi.
But first I tryed to used a float factor by returning:
return ((float) devDpi) / screenDpi;
And this was clearly wrong, (the page was clearly scaled too much as if
3 was right but 300.0 / 96.0 was not).
I'm kind of confused about that, I would have expect the float division
to be right.
Any thoughts?
Also whatever I do the System.Windows.Forms.PrintPreviewDialog still
display no text at all.... :-/
message I'm trying to print some of my document.
The problem is, the rendering of the document is not done through
GDI+ at all but through plain old GDI, and I need it like that as I
am using Uniscribe to layout text.
Anyway, when printing the text is completely out of place, I wonder
if it's due to incorrrect Dpi settings? (or something /else/?)
I will investigate that.....
Anyway if any of you had similar experience and could shed some
light?
Here is how I initialize my HDC (Managed C++):
====================
struct HDCInfo
{
HDC hdc;
// to be restored HGDIOBJ font0;
HGDIOBJ brush0;
HGDIOBJ pen0;
XFORM transform0;
};
void NText::ScriptAnalysis::GetHDC(Graphics^ g, struct HDCInfo& info)
{
array<float>^ matrix = g->Transform->Elements;
pin_ptr<float> p_transform = &matrix[0];

info.hdc = (HDC)(void*)g->GetHdc(true);
info.font0 = ::GetCurrentObject(info.hdc, OBJ_FONT);
info.brush0 = ::GetCurrentObject(info.hdc, OBJ_BRUSH);
info.pen0 = ::GetCurrentObject(info.hdc, OBJ_PEN);
::GetWorldTransform(info.hdc, &info.transform0);

::SetGraphicsMode(info.hdc, GM_ADVANCED);
::SetBkMode(info.hdc, TRANSPARENT);
::SetWorldTransform(info.hdc, (XFORM*) p_transform);
}
====================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Mixing GDI+ & GDI drawing 0

Top