Discussion:
Printing, Header and Footer Shifts on Pages 2-N
(too old to reply)
m***@gmail.com
2014-06-03 17:06:18 UTC
Permalink
I'm having an unnecessarily difficult time getting printing to work. For
now I'm testing with the Microsoft XPS Document Writer. By default it has
no margins so the page size equals the printable size. I figured this would
be a good place to start although my code should take margins into effect
for normal printers. If I am simply printing the Scintilla contents only
everything looks good. Alignment of the text is correct, each page prints
properly, etc. When I add header/footer text the first page looks perfect.
Everything is painted where it should be. Pages 2-N are different. My
header/footer are both shifted up by 11 pixels. The Scintilla painted
region is still properly positioned. If I replace the call to
SCI_FORMATRANGE with an increment of my lengthPrinted variable (same logic
as done in SciTE) by 1000 each iteration to simulate printing and getting
through the loop with 2+ pages the header and footer are properly
positioned.

So, to recap...

1. Header/footer display properly on page 1, but are both shifted up 11
pixels on pages 2-N. The up shift is the same on each page 2-N, it's not 11
on page two, 22 on page three, etc.
2. Removing SCI_FORMATRANGE and simulating multiple pages does not create a
header/footer shift, they are properly positioned.

My code is a near clone of SciTE's logic. I've omitted the custom margin
setting stuff because we print only using the printer's margins and don't
allow the user to specify their own. I'm a Delphi developer and have been
using the TCanvas methods like TextOut and TextExtent to draw text and get
text sizes, but I've also tried the Windows API calls directly like
DrawTextW and creating clipping regions, etc. and I get the same behavior
regardless of the approach.

The attached file is my "printed" document that shows the problem I'm
having.

Any help or guidance is greatly appreciated. I've already scoured the SciTE
code to death and don't see anything functionally different.

Thanks,
Michael

PS. In the SciTE code I see wEditor.Call(SCI_FORMATRANGE, FALSE, 0); at the
end of printing, but the documentation does not mention this as a necessary
step. I've put in it my code since you're doing so in SciTE, but do you
have any additional explanation for doing so? My C is not as good, but it
looks like an unnecessary step that just returns 0 when I examine
FormatRange in the source.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/d/optout.
Neil Hodgson
2014-06-03 23:25:37 UTC
Permalink
1. Header/footer display properly on page 1, but are both shifted up 11 pixels on pages 2-N. The up shift is the same on each page 2-N, it's not 11 on page two, 22 on page three, etc.
2. Removing SCI_FORMATRANGE and simulating multiple pages does not create a header/footer shift, they are properly positioned.
Most likely some actions on the HDC are leaking out and affecting you such as font or alignment. Check closely to ensure you are calling every API like SciTE. Draw both text and some lines/rectangles to determine if all drawing is shifted. Its easy to get the lifetime of drawing objects wrong - the Delphi version could be doing something clever like caching. Also check any initialisation code for potential mode differences.
PS. In the SciTE code I see wEditor.Call(SCI_FORMATRANGE, FALSE, 0); at the end of printing, but the documentation does not mention this as a necessary step. I've put in it my code since you're doing so in SciTE, but do you have any additional explanation for doing so?
SCI_FORMATRANGE is based on EM_FORMATRANGE for the Windows Rich Edit control which uses a call with a NULL parameter to free any caches used in printing. I included it in case caching was needed.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb788020(v=vs.85).aspx

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/d/optout.
m***@gmail.com
2014-06-04 14:11:45 UTC
Permalink
Thanks, Neil. I'll make another pass and see what I can find out.

Michael
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/d/optout.
m***@gmail.com
2014-06-04 15:49:18 UTC
Permalink
Post by Neil Hodgson
Most likely some actions on the HDC are leaking out and affecting you
such as font
Thanks, that was it. When I tried the API calls directly I neglected to
create a font. Instead I was relying on the font object of Delphi's
TCanvas. Creating my own font solved the issue.

Michael
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/d/optout.
m***@gmail.com
2014-06-04 16:03:03 UTC
Permalink
Correction, it was the alignment as you suggested. I can still use my
TCanvas object which makes the code a bit more readable.
Post by Neil Hodgson
Most likely some actions on the HDC are leaking out and affecting you
Post by Neil Hodgson
such as font
Thanks, that was it. When I tried the API calls directly I neglected to
create a font. Instead I was relying on the font object of Delphi's
TCanvas. Creating my own font solved the issue.
Michael
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...