Hot Topic (More than 10 Replies) PrintString plotting inaccurately (Read 2269 times)
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
PrintString plotting inaccurately
May 22nd, 2005 at 7:50pm
Print Post Print Post  
I am confused by the inaccuracy of plotting where PrintString is printing.

I was originally using a NewPage(850, 1100) setting for printing my checks, but that grid was too coarse. It caused my signature graphic to look rough. I increased the NewPage values to get a finer grid, in order to provide a better quality signature. That improves the image quality, but causes the X Y coordinates to become increasingly inaccurate the finer I make the grid.

I set up the code with variables that will multiply all of the coordinates by the same factor, which I thought should maintain the correct ratios for the X Y coordinate placement of the printed data. The larger the factor, the shorter the distance from the top and left edges of the paper the data is placed. (I hope I am explaining this clearly.)

This is the code I am using. What am I overlooking here?
Code
Select All
var vCheckDate as String = @Rt("00" + @Str(@Month(Check Date)), 2) + "-" + @Rt("00" + @Str(@DOM(Check Date)), 2) + "-" + @Year(Check Date)
var vAmount as String = @Decimals(Amount, 2)
var vFont as String = "Courier New"	//Font Face
var vSize as Int			//Font Size
var vDPI as Int = 100			//Dots Per Inch

vSize = .16 * vDPI

//Format is Inches * DPI
NewPage(8.50 * vDPI, 11.00 * vDPI)
PrintPagePaper(28)

//Check data
PrintString(Check No, 7.60 * vDPI, .50 * vDPI, 0, vFont, vSize, 0)
PrintString(vCheckDate, 7.10 * vDPI, .85 * vDPI, 0, vFont, vSize, 0)
PrintString(Name, 1.10 * vDPI, 1.35 * vDPI, 0, vFont, vSize, 0)
PrintString(vAmount, 7.00 * vDPI, 1.35 * vDPI, 0, vFont, vSize, 0)
PrintString(Dollars, .40 * vDPI, 1.70 * vDPI, 0, vFont, vSize, 0)
PrintString(Memo, .70 * vDPI, 2.85 * vDPI, 0, vFont, vSize, 0)

//PrintImage(file, xpos, ypos, width, height)
PrintImage(".\Data\Sig.png", 5.40 * vDPI, 2.55 * vDPI, 2.80 * vDPI, .60 * vDPI)
 


  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: PrintString plotting inaccurately
Reply #1 - May 22nd, 2005 at 9:43pm
Print Post Print Post  
Hi Carl....

This is still confusing, but I think that you only need to multiply the NewPage and vSize numbers by the constant.  I don't think you need to do that inside each PrintString/Image line for the x/y pos values.

I may be wrong, but this may help until Lanticans show up.

Also see pages 14,15 of May 2005 issue of Inside Sesame.  Excellent article from Alec.
« Last Edit: May 23rd, 2005 at 1:55am by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: PrintString plotting inaccurately
Reply #2 - May 23rd, 2005 at 12:41pm
Print Post Print Post  
Hi Bob,

I multiply each value by the vDPI factor so that I can change the dots per inch setting once, and have all of the coordinates scale to match it.

Regarding Alec's article: I just finished reading it, and that's when I added the PrintPagePaper command to the code. This problem has been bugging me for a while, and I thought that maybe this command would somehow help the situation. When I did not, I finally became motivated to find out why scaling the values for a finer grid causes everthing to shrink closer to the starting edges of the paper.

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: PrintString plotting inaccurately
Reply #3 - May 23rd, 2005 at 2:04pm
Print Post Print Post  
Carl,
From what I can see the values you are using a equal to or below 850 x 1100. For example, the NewPage command:
Code
Select All
 NewPage(8.50 * vDPI, 11.00 * vDPI)
 


with vDPI set to 100, results in 850 x 1100. Try setting vDPI to the actual resolution of your printer per inch. This is likely to be either 300 or 600, though it might be as high as 2400.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: PrintString plotting inaccurately
Reply #4 - May 24th, 2005 at 1:06am
Print Post Print Post  
Mark,

Yes, 850 x 1100 is what I want to use right now, as it is equal to the original values when I first programmed the code. So currently this is the setting that gets my data to print where it needs to. The only reason I wanted to change the grid resolution was because my signature graphic was too choppy-looking at this setting. I added the vDPI variable was so I could experiment with different resolutions by changing just one number.

The problem is when I use higher resolutions, the printing locations of the text moves further to the left and higher. But if the X Y coordinates are being scaled up by the SAME factor as the page dimensions, why wouldn't the end result be that the text prints to the same relative position on the page?
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: PrintString plotting inaccurately
Reply #5 - May 24th, 2005 at 1:49am
Print Post Print Post  
Mark,

I just printed some test pages using various vDPI settings. Each time that value is increased, the placement of the text is shifted to the left (and up).

I want the Check No element to start at 7.6" from the left of the page. When vDPI is 100, it prints at the desired location. When I increase vDPI the Check No element creeps to the left, printing at
7.4" when vDPI is set to 600,
7.15" when vDPI is 1200,
6.75 when vDPI is 2400, etc.

And strangely, the size of the font scales correctly until the setting of 2400, at which point the text is so small, I can barely read it. Why would it scale in sync sometimes, then suddenly not scale correctly?
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: PrintString plotting inaccurately
Reply #6 - May 24th, 2005 at 3:10am
Print Post Print Post  
Carl,

I see two things that may be affecting you.

1. You need a space before the font name to indicate a normal (not bold or italic) font.
" Courier New"
This can have an effect, in that, if Sesame can't find a matching font name, substitution may occur, which can affect text measurement.

2. At the ratio shown in your code, your font is scaled to be only 1/16" tall. This is very tiny. Courier New is not a fully scalable font. This means that the OS must substitute the closest available size it can find. Again, this can affect measurement.   

Try it with a space in front of the font name and a larger font size and see what happens. You may also see a difference by using a TrueType font, such as Lucida Console.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: PrintString plotting inaccurately
Reply #7 - May 24th, 2005 at 4:18am
Print Post Print Post  
Hello Erika,

Quote:
your font is scaled to be only 1/16" tall.

Actually, I disagree.Wink  That would be .16 inches (16 hundredths, not 0.0625") tall, which is slightly less than a 12 point font size. (If 72 points = 1 inch, then .16" x 72 = 11.52 points.)

Quote:
Try it with a space in front of the font name and a larger font size and see what happens. You may also see a difference by using a TrueType font, such as Lucida Console.

I tried it with " Arial" and " Lucida Console" including spaces -- same results as my previous post.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: PrintString plotting inaccurately
Reply #8 - May 24th, 2005 at 11:56am
Print Post Print Post  
Quote:
Hello Erika,

Actually, I disagree.Wink  That would be .16 inches (16 hundredths, not 0.0625") tall, which is slightly less than a 12 point font size. (If 72 points = 1 inch, then .16" x 72 = 11.52 points.)


Yes, OK.  Grin

That's what I get for trying to do math without mechanical assistance. *sigh*

What printer are you using?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: PrintString plotting inaccurately
Reply #9 - May 24th, 2005 at 12:37pm
Print Post Print Post  
Okay, I forgive you. Grin  Plus, it was pretty late - maybe you were actually sleep typing.

Quote:
What printer are you using?

I am using an HP 895Cse, which has a resolution of 600 dpi. That's why I'm confused. I thought that if I used the native resolution of the printer, I should get the most accurate results. But the most accurate results are at 100 dpi. ???
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: PrintString plotting inaccurately
Reply #10 - May 24th, 2005 at 1:40pm
Print Post Print Post  
Carl,

After playing with this on a number of different printers, we think that you are just seeing the effect of an accumulation of factors. The factors include things like:
1. The printer is mechanical. It will not pull/feed two sheets of paper exactly the same way.
2. On a inkjet a "dot" tends to be considerably taller than it is wide, rather than being square. Inkjets generally have much higher horizontal resolution than vertical.
3. Your particular printer is really 600dpi. It uses "color layering" to get higher resolutions for color.
4. Font descriptors have their own rules about which fonts can scale to what sizes and how well they can do any particular size.
5. On MS, scaling is done with integer math. This can introduce "inaccuracies" due to truncation which can accumulate.
6. Your printer dirver has settings like "Best" and "Economode" which can drastically affect how it renders any given dot.
7. Your math may cause a dot to land at a place that is not mechanically accessible by the printer, especially if NewPage is used to create a higher set of divisions than the printer can do. The printer can only print on certain mechanical divsions.   

Etc...

Bottom line, you can't always work the math with printers based on "it should theoretically work". You should be able to use the math to get it basically into place, then adjust as needed. If your printer produces the results you prefer at a scaling factor of 100, then that's the one you should use. To improve the quality of your signature at this resolution, what you want to do is scan the signature at a high resolution, then scale it down for print. Images tend to get "rough" when they are scaled up from their natural size.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: PrintString plotting inaccurately
Reply #11 - May 24th, 2005 at 9:53pm
Print Post Print Post  
Quote:
1. The printer is mechanical. It will not pull/feed two sheets of paper exactly the same way.

Each of the measurements in the previous posts can be reproduced almost exactly time after time.

Quote:
3. Your particular printer is really 600dpi. It uses "color layering" to get higher resolutions for color.

Yes, I know. Not using color in this case.

Quote:
5. On MS, scaling is done with integer math. This can introduce "inaccuracies" due to truncation which can accumulate.

This seems like to most likely cause. But that raises the question, how do other programs achieve printing precision?

Quote:
...what you want to do is scan the signature at a high resolution, then scale it down for print. Images tend to get "rough" when they are scaled up from their natural size.

The image also gets "rough" when it is scaled down from a large natural size to a grid of 100 dpi. (I know, because my image is actually 2940 x 630, scaled down to 280 x 60 in PrintImage, when using 100 dpi.) That's why I tried the 600 dpi setting. And that's when I discovered the creeping to the left and top.

I guess the bottom line is that I will simply have to use 600 dpi, and experiment with the X Y coordinates. I thought I must have been overlooking something. I just expected that scaling everything by the same factor would keep the text in the same place. Plus, I hate experimenting like that. I would much prefer to simply take measurements, and plug in the correct coordinates. Sad

Thanks,
Carl
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: PrintString plotting inaccurately
Reply #12 - May 25th, 2005 at 4:06am
Print Post Print Post  
Problem solved! Smiley

I modified the code. It now produces VERY PRECISE results. I can simply measure where I want the text to print, plug in the coordinates, and be sure that it will print where I want.

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: PrintString plotting inaccurately
Reply #13 - May 25th, 2005 at 12:26pm
Print Post Print Post  
Quote:
Problem solved! Smiley

I modified the code. It now produces VERY PRECISE results. I can simply measure where I want the text to print, plug in the coordinates, and be sure that it will print where I want.


Great! What solved it for you?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: PrintString plotting inaccurately
Reply #14 - May 25th, 2005 at 2:05pm
Print Post Print Post  
I added two more variables to the code (vX & vY) that deal with the aspect ratio differences of the X Y coordinates. Now, if I enter 7 to indicate 7" on the X axis, I get the text starting at EXACTLY 7" from the left edge of the paper.

I also provided a calcluation so that I can enter the font size expressed in points, that matches the true point sizes specified in MS Word and other Windows programs.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged