Printing part of card

Need help with a script? This is the place to discuss how to get your code running!

Printing part of card

Postby sctell » Mon Jan 30, 2017 2:25 am

In creating a pie chart I have a routine that places labels on the circumference of the chart.

I have noted a discrepancy when printing:

On calling this routine:

Code: Select all
on printChart
    lock screen
    open pageSetup
    put the rect of me into tOldRect
    put the printableRect into tRect
    set the rect of me to tRect
    createChart
    print card from the topLeft of me to the bottomRight of me with dialog
    set the rect of me to tOldRect
    createChart
    unlock screen
end printChart


I get part of a label missing when I view in Preview. See images below.

I just thought (while typing this) that while adjusting the size of the chart to the printableRect that part of the chart may go offscreen.

If this is the case then is the print area truncated and is that the expected behaviour?

Screen Shot 1.png
Screen Shot 1.png (11.89 KiB) Viewed 277 times


Screen Shot.png
Screen Shot.png (13.3 KiB) Viewed 277 times



All the best

Terry
sctell
 
Posts: 1071
Joined: Sun Jul 06, 2008 10:41 am

Re: Printing part of card

Postby sctell » Mon Jan 30, 2017 2:39 am

It does not appear to be an offscreen issue, rather a width of the field issue.

I use this, found in the help guide, to size the width of the field:

----------
put textMargins(tObj) into tM
put item 1 of tM + item 3 of tM + textWidthMax(tObj) into tLabelWidth
set the width of tObj to tLabelWidth
----------

If I add another arbitrary 10 to the field width then it prints OK.

Is the above the correct way to calculate the width of the field.

I suppose textMargins is the only variable in the above. I use whatever the default margins are after creating the field.

The margins returned are 4,2,4,2

Does this vary when using:

set the textFont to ...
set the textSize to ...
new field

All the best

Terry
sctell
 
Posts: 1071
Joined: Sun Jul 06, 2008 10:41 am

Re: Printing part of card

Postby sctell » Mon Jan 30, 2017 2:46 am

I suppose the question is still valid.

Why does the text not display correctly in Preview but does in SC?

Is there a bug somewhere in the conversion from SC Text to Preview (PDF?)?


All the best

Terry
sctell
 
Posts: 1071
Joined: Sun Jul 06, 2008 10:41 am

Re: Printing part of card

Postby codegreen » Tue Jan 31, 2017 12:51 pm

Unfortunately nowadays when you print a non-rasterized job it goes through an internal translation step (i.e., within the printing system) from QD to PDF after it leaves our hands which may subtly affect layout (and particularly text metrics).

So yes I guess you could say it's a bug. Just not a bug in SuperCard, and thus not one I can directly address...

If you print 'rasterized' this probably won't happen (as in effect you'll be printing a high-res bitmap generated via QD instead of vectors), though of course depending on the size of your image you may encounter other constraints you like even less.

-Mark
codegreen
 
Posts: 1425
Joined: Mon Jul 14, 2008 11:03 pm

Re: Printing part of card

Postby sctell » Wed Feb 01, 2017 6:17 am

codegreen wrote:If you print 'rasterized' this probably won't happen (as in effect you'll be printing a high-res bitmap generated via QD instead of vectors), though of course depending on the size of your image you may encounter other constraints you like even less.


I can imagine the quality will suffer.

I will leave my arbitrary length adjustment in place.

All the best

Terry
sctell
 
Posts: 1071
Joined: Sun Jul 06, 2008 10:41 am

Re: Printing part of card

Postby codegreen » Wed Feb 01, 2017 1:32 pm

If you haven't already, one thing you should do is check is that you've got Preview set up to actually display what you're giving it (which IIRC is NOT the default setting).

That is, open its prefs, choose the PDF tab, and select 1 point equals 1 screen pixel and uncheck Smooth text and line art.

This should at least help narrow down where things are getting munged...

-Mark
codegreen
 
Posts: 1425
Joined: Mon Jul 14, 2008 11:03 pm

Re: Printing part of card

Postby sctell » Thu Feb 02, 2017 12:18 am

codegreen wrote:This should at least help narrow down where things are getting munged...


It certainly does, because I actually have 2 print routines, the one I originally posted and this one:

Code: Select all
lock screen
open pageSetup
print card from the topLeft of me to the bottomRight of me scale with dialog
unlock screen


It is this one that is causing the problem NOT the one at the top of this thread. :oops:

Does this make any difference to your thinking?


All the best

Terry
sctell
 
Posts: 1071
Joined: Sun Jul 06, 2008 10:41 am

Re: Printing part of card

Postby sctell » Thu Feb 02, 2017 4:29 am

sctell wrote:print card from the topLeft of me to the bottomRight of me scale with dialog



If I remove the scale parameter the fields print correctly.


All the best

Terry
sctell
 
Posts: 1071
Joined: Sun Jul 06, 2008 10:41 am

Re: Printing part of card

Postby codegreen » Thu Feb 02, 2017 11:01 am

Does this make any difference to your thinking?

LOL! Yes, it means the problem is in a DIFFERENT part of Apple's code... ;)

When you specify the scale option your print job is captured to a vector PICT that's then drawn into the calculated destination rectangle of an offscreen PixMap and rasterized in-place (mainly to insulate it from the text metric and pattern scaling vagaries often associated with subsequent QD->PS/PDF conversion/scaling). The output from this step is in effect a pixel-for-pixel snapshot of the scaled vector PICT exactly as QuickDraw has rendered it.

So unfortunately it appears that initial scaling (of the vector PICT) is what's Borking your text metrics, as the damage is evidently already done before you reach the previously-suspect step of rendering into a CGContext for printing. I can whuff up an external to make SC dump the interim rasterized PICT to a file so you can inspect it if you want to confirm this at your end.

I guess my next question then is what EXACTLY are you trying to accomplish here? There may be other devious workarounds available depending on your specific goal...

-Mark
codegreen
 
Posts: 1425
Joined: Mon Jul 14, 2008 11:03 pm

Re: Printing part of card

Postby sctell » Thu Feb 02, 2017 12:17 pm

codegreen wrote:So unfortunately it appears that initial scaling (of the vector PICT) is what's Borking your text metrics, as the damage is evidently already done before you reach the previously-suspect step of rendering into a CGContext for printing. I can whuff up an external to make SC dump the interim rasterized PICT to a file so you can inspect it if you want to confirm this at your end.


If your pretty sure this is the issue then probably there is no need for this additional confirmation effort?

codegreen wrote:I guess my next question then is what EXACTLY are you trying to accomplish here? There may be other devious workarounds available depending on your specific goal...


So this is the offending SC code:

Code: Select all
on printChartScaleToFit
    -- THIS ROUTINE GIVES A DEFECT IN PRINT PREVIEW
    lock screen
    open pageSetup
    print card from the topLeft of me to the bottomRight of me scale with dialog
    unlock screen
end printChartScaleToFit


As I drag the window larger/smaller I reposition/resize the objects necessary to make a pie chart or bar chart. (This now works well and smoothly)

At this point the graphic rectangle(me) may be larger or smaller than the print rectangle.

I want to ensure that all objects will be printed.

The above routine ensures that the print output will fit the print rectangle ensuring that all the objects are printed.

"Me" is just a graphic rectangle used as the boundary for all the objects.

Devious workaround awaited. ;)

All the best

Terry
sctell
 
Posts: 1071
Joined: Sun Jul 06, 2008 10:41 am

Re: Printing part of card

Postby codegreen » Thu Feb 02, 2017 3:12 pm

Well to begin with if you now have code to quickly resize the chart at will, why can't you just lock the screen, resize it to actually fit the print rectangle, print it, resize it back (or revert), and unlock the screen again?

Not very sexy or high-tech I know, but...

-Mark
codegreen
 
Posts: 1425
Joined: Mon Jul 14, 2008 11:03 pm

Re: Printing part of card

Postby sctell » Fri Feb 03, 2017 12:09 am

codegreen wrote:Well to begin with if you now have code to quickly resize the chart at will, why can't you just lock the screen, resize it to actually fit the print rectangle, print it, resize it back (or revert), and unlock the screen again?

Not very sexy or high-tech I know, but...

-Mark



That's actually what the routine does in the first post of the thread.

The difficulty is when the chart has a legend with a lot of bars or segments. As I don't size the actual legend area but just specify it in a user prop to prevent the legend overwhelming the size of the chart I wanted the scale facility so the user if he/she chooses could print what they actually see on the screen. I am sure there are ways to capture the screen image and print that but your method in SC results in high quality output.

I can't think of a solution so perhaps just increasing the width of the field to try and compensate for the error is not a stupid idea.
I wonder if it simply a rounding error in Apple's calculations as I only need to add 1 to the field width and it goes away?

EDIT: It probably also only shows when i use a ) at the end of the text as ) will push up against the end of the field?

EDIT2: Adding 1 is not sufficient, so decided to add item 1 of the margins to the width. Does the margin change depending on the size of the text? or is it fixed at 4,2,4,2?

All the best

Terry
sctell
 
Posts: 1071
Joined: Sun Jul 06, 2008 10:41 am

Re: Printing part of card

Postby codegreen » Fri Feb 03, 2017 7:12 am

The margins aren't affected by the field's contents.

-Mark
codegreen
 
Posts: 1425
Joined: Mon Jul 14, 2008 11:03 pm

Re: Printing part of card

Postby sctell » Fri Feb 03, 2017 8:13 am

codegreen wrote:The margins aren't affected by the field's contents.


Thanks.

I have decided to calculate the space needed to display the full Legend.Whats left is available for the chart.

This then allows me to implement your suggestion to resize while the screen is locked print and then put everything back.

I have implemented as this:

Code: Select all
on printChart
    lock screen
    open pageSetup
    put the rect of me into tOldGrcRect
    put the printableRect into tRect
    set backSize of this background to item 3 of tRect,item 4 of tRect
    set the rect of me to tRect
    createChart
    print card from the topLeft of me to the bottomRight of me with dialog
    set the backSize of this bg to the windowSize of this wd
    set the rect of me to tOldGrcRect
    createChart
    unlock screen
end printChart



All the best

Terry
sctell
 
Posts: 1071
Joined: Sun Jul 06, 2008 10:41 am


Return to Scripting in SuperTalk

Who is online

Users browsing this forum: No registered users and 2 guests

cron