You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Guess Who <da...@yahoo.com> on 2003/10/29 17:59:11 UTC

Rasterized Image Pixels not aligned with SVG Source

I'm having a little trouble with images that were
transcoded with batik.  In particular, I'm working
with svg documents that contain almost all text
elements.  When the doc is transcoded into an image,
coords of the text that appears in the image don't
seem to correspond with the coords specified in the
svg doc. 

I've already taken into account the aspectratio in
testing the coords' congruency.  

Aspectratio = imgwidth/svg:aoiwidth

the aoi that i'm using is the rect element just inside
the page group.

For instance, xcoord:image  = xcoord:svgdoc *
aspectratio

Correct me if I am wrong about the above calcs.  Here
is the svg doc...

Thanks,
Dave

<?xml version="1.0" encoding="ISO-8859-1"?>
<svg contentScriptType="text/ecmascript" width="612.0"
     xmlns:xlink="http://www.w3.org/1999/xlink"
zoomAndPan="magnify"
     contentStyleType="text/css" height="792.0"
     preserveAspectRatio="xMidYMid meet"
xmlns="http://www.w3.org/2000/svg"
     version="1.0">
    <g id="Page-1"
style="font-family:sanserif;font-size:12"
       transform="translate(0,0.0)">
        <rect width="612.0" x="0.0" height="792.0"
y="0.0"
              style="fill:none;stroke:black"/>
        <text x="144.98" y="83.974976"
style="font-size:14.0;font-weight:bold">
            Championzone
        </text>
        <text x="250.75" y="83.974976"
style="font-size:14.0;font-weight:bold">
            Certificati.n
        </text>
        <text x="333.204" y="83.974976"
style="font-size:14.0;font-weight:bold">
            and
        </text>
        <text x="363.537" y="83.974976"
style="font-size:14.0;font-weight:bold">
            Course
        </text>
        <text x="417.214" y="83.974976"
style="font-size:14.0;font-weight:bold">
            System
        </text>
        <text x="272.543" y="100.92499"
style="font-size:14.0;font-style:italic">
            Use
        </text>
        <text x="302.884" y="100.92499"
style="font-size:14.0;font-style:italic">
            cases
        </text>
        <text x="90.0" y="134.82501"
style="font-size:14.0;font-weight:bold">
            Use
        </text>
        <text x="121.127" y="134.82501"
style="font-size:14.0;font-weight:bold">
            Ca,e
        </text>
        <text x="156.143" y="134.82501"
style="font-size:14.0;font-weight:bold">
            Descr.ption:
        </text>
        <text x="243.259" y="134.82501"
style="font-size:14.0;font-weight:bold">
            Take
        </text>
        <text x="280.613" y="134.82501"
style="font-size:14.0;font-weight:bold">
            Cer,ificat,on
        </text>
        <text x="366.956" y="134.82501"
style="font-size:14.0;font-weight:bold">
            Cour.e
        </text>
        <text x="90.0" y="151.77502"
style="font-size:14.0;font-style:italic">
            Precondition
        </text>
        <text x="167.824" y="151.77502"
style="font-size:14.0">
            :
        </text>
        <text x="177.158" y="151.77502"
style="font-size:14.0">
            The
        </text>
        <text x="206.726" y="151.77502"
style="font-size:14.0">
            person
        </text>
        <text x="254.977" y="151.77502"
style="font-size:14.0">
            plans
        </text>
        <text x="293.89" y="151.77502"
style="font-size:14.0">
            to
        </text>
        <text x="311.01" y="151.77502"
style="font-size:14.0">
            r,.-.ter
        </text>
        <text x="353.783" y="151.77502"
style="font-size:14.0">
            f.r,a
        </text>
        <text x="383.343" y="151.77502"
style="font-size:14.0">
            certification
        </text>
        <text x="459.591" y="151.77502"
style="font-size:14.0">
            course.
        </text>
        <text x="90.0" y="168.72498"
style="font-size:14.0;font-style:italic">
            Main
        </text>
        <text x="125.789" y="168.72498"
style="font-size:14.0;font-style:italic">
            flow
        </text>
        <text x="156.129" y="168.72498"
style="font-size:14.0;font-style:italic">
            of
        </text>
        <text x="173.249" y="168.72498"
style="font-size:14.0;font-style:italic">
            events
        </text>
        <text x="214.496" y="168.72498"
style="font-size:14.0">
            :
        </text>
        <text x="223.83" y="168.72498"
style="font-size:14.0">
            The
        </text>
        <text x="253.398" y="168.72498"
style="font-size:14.0">
            use
        </text>
        <a xlink:href="#svgView(viewBox(0, 0.0, 612,
792))" xlink:type="simple"
           xlink:actuate="onRequest"
xlink:show="replace"
           xmlns:xlink="http://www.w3.org/1999/xlink">
            <rect width="306.0" x="0.0" height="792.0"
y="0.0"
                 
style="fill:blue;visibility:hidden"/>
        </a>
    </g>
</svg>

__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Rasterized Image Pixels not aligned with SVG Source

Posted by Guess Who <da...@yahoo.com>.
Actually, I'm not sure how to use viewPort in this
example.  Should I specify the viewbox to be (0,0,
612,792)?  

How would I use the transcoder code with the viewbox?

One reason I don't use the viewbox is because I will
be using this program to handle svgdocs with more than
one page (more than one <g> tag). I intend to
enumerate through each <g> tag and transcode an image
for each group specifying a aoi that corresponds to
each rect.  Can I do this with viewbox? 

I compared the coords differences at the top and the
bottom coord and they are both off by about 8 pixels. 
The xcoords are not off at all. 

I am using a borderlayout and I am adding a canvas
(that draws the image) to the center.  I think if I
pad the canvas at the top with 8 pixels, I can
workaround the problem.  

The fact that the xcoords are fine, but the ycoords
are off by a fixed amount, makes me think that my
problem is the placement of the image in the canvas,
even though i place it at 0,0. 

--- Thomas DeWeese <Th...@Kodak.com> wrote:
> Guess Who wrote:
> 
> > Yes actually there is a lot more to the story. I'm
> not
> > using the rasterizer, I'm using the transcoder. 
> > 
> > I am getting the rect width from the doc which is
> 612.
> > 
> > I need to scale the image down to 500 width so I
> get
> > the "scale factor" = 500/612 = .817
> 
>    Hmm is there a reason that using the 'viewBox'
> attribute
> on the outermost SVG wouldn't do what you want?
> (auto
> scale to fit viewing conditions).
> 
>    The code looks reasonable.
> 
> > Now when I view the image in an applet using awt,
> I
> > capture some elementary mouse events.  When I
> place
> > the mouse pointer on the upper-leftmost corner of
> the
> > upper-leftmost text letter in the awt image, I get
> a Y
> > coord of about 61.  Now when we look at the svg
> code
> > the uppermost text is positioned at about 84 and
> with
> > the scaleFactor, it translates to about 69.  It is
> off
> > by  69-61 = 8 pixels. 
> 
>    How certain are you that you are properly
> interpreting the
> mouse coords?  Does the error seem to 'scale' so
> it's larger
> at the right/bottom compared with left/top?
> 
> > I think you are right and I am probably using the
> > transcoding process wrong, but I'm not sure what
> to
> > do... 
> 
>    I would try using viewBox rather than mucking
> with the
> AOI.
> 
> > 
> > Thanks for your help with this.
> > 
> > --- Thomas DeWeese <Th...@Kodak.com>
> wrote:
> > 
> >>Guess Who wrote:
> >>
> >>David? :)
> >>
> >>
> >>>I'm having a little trouble with images that were
> >>>transcoded with batik.  In particular, I'm
> working
> >>>with svg documents that contain almost all text
> >>>elements.  When the doc is transcoded into an
> >>
> >>image,
> >>
> >>>coords of the text that appears in the image
> don't
> >>>seem to correspond with the coords specified in
> >>
> >>the
> >>
> >>>svg doc. 
> >>>
> >>>I've already taken into account the aspectratio
> in
> >>>testing the coords' congruency.  
> >>>
> >>>Aspectratio = imgwidth/svg:aoiwidth
> >>
> >>    Actually the proper name for this is the
> 'scale
> >>factor'.
> >>The Aspect ratio is typically the width/height (or
> >>vice versa).
> >>
> >>
> >>>the aoi that i'm using is the rect element just
> >>
> >>inside
> >>
> >>>the page group.
> >>
> >>   Well that is the same as the default area of
> the
> >>SVG
> >>so the scale factor here should be 1 (as is when I
> >>tested it).
> >>
> >>
> >>>For instance, xcoord:image  = xcoord:svgdoc *
> >>>aspectratio
> >>>
> >>>Correct me if I am wrong about the above calcs. 
> >>
> >>Here
> >>
> >>>is the svg doc...
> >>
> >>   In the future using an attachment works much
> >>better as often
> >>things get munged by line-wrapping.  Also how are
> >>you generating
> >>the image?  When I use the svgrasterizer I get
> text
> >>exactly where
> >>I think it should be:
> >>
> >>./build.sh svgrasterizer -a 0,0,612,792 text.svg
> >>
> >>   But since your image seems to be scaled somehow
> I
> >>must assume
> >>you are not using the default w/h for rendering.
> >>
> >>
> >>
> >>
> > 
> >
>
---------------------------------------------------------------------
> > 
> >>To unsubscribe, e-mail:
> >>batik-users-unsubscribe@xml.apache.org
> >>For additional commands, e-mail:
> >>batik-users-help@xml.apache.org
> >>
> > 
> > 
> > 
> > __________________________________
> > Do you Yahoo!?
> > Exclusive Video Premiere - Britney Spears
> > http://launch.yahoo.com/promos/britneyspears/
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> batik-users-unsubscribe@xml.apache.org
> > For additional commands, e-mail:
> batik-users-help@xml.apache.org
> > 
> 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail:
> batik-users-help@xml.apache.org
> 


__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Rasterized Image Pixels not aligned with SVG Source

Posted by Thomas DeWeese <Th...@Kodak.com>.
Guess Who wrote:

> Yes actually there is a lot more to the story. I'm not
> using the rasterizer, I'm using the transcoder. 
> 
> I am getting the rect width from the doc which is 612.
> 
> I need to scale the image down to 500 width so I get
> the "scale factor" = 500/612 = .817

   Hmm is there a reason that using the 'viewBox' attribute
on the outermost SVG wouldn't do what you want? (auto
scale to fit viewing conditions).

   The code looks reasonable.

> Now when I view the image in an applet using awt, I
> capture some elementary mouse events.  When I place
> the mouse pointer on the upper-leftmost corner of the
> upper-leftmost text letter in the awt image, I get a Y
> coord of about 61.  Now when we look at the svg code
> the uppermost text is positioned at about 84 and with
> the scaleFactor, it translates to about 69.  It is off
> by  69-61 = 8 pixels. 

   How certain are you that you are properly interpreting the
mouse coords?  Does the error seem to 'scale' so it's larger
at the right/bottom compared with left/top?

> I think you are right and I am probably using the
> transcoding process wrong, but I'm not sure what to
> do... 

   I would try using viewBox rather than mucking with the
AOI.

> 
> Thanks for your help with this.
> 
> --- Thomas DeWeese <Th...@Kodak.com> wrote:
> 
>>Guess Who wrote:
>>
>>David? :)
>>
>>
>>>I'm having a little trouble with images that were
>>>transcoded with batik.  In particular, I'm working
>>>with svg documents that contain almost all text
>>>elements.  When the doc is transcoded into an
>>
>>image,
>>
>>>coords of the text that appears in the image don't
>>>seem to correspond with the coords specified in
>>
>>the
>>
>>>svg doc. 
>>>
>>>I've already taken into account the aspectratio in
>>>testing the coords' congruency.  
>>>
>>>Aspectratio = imgwidth/svg:aoiwidth
>>
>>    Actually the proper name for this is the 'scale
>>factor'.
>>The Aspect ratio is typically the width/height (or
>>vice versa).
>>
>>
>>>the aoi that i'm using is the rect element just
>>
>>inside
>>
>>>the page group.
>>
>>   Well that is the same as the default area of the
>>SVG
>>so the scale factor here should be 1 (as is when I
>>tested it).
>>
>>
>>>For instance, xcoord:image  = xcoord:svgdoc *
>>>aspectratio
>>>
>>>Correct me if I am wrong about the above calcs. 
>>
>>Here
>>
>>>is the svg doc...
>>
>>   In the future using an attachment works much
>>better as often
>>things get munged by line-wrapping.  Also how are
>>you generating
>>the image?  When I use the svgrasterizer I get text
>>exactly where
>>I think it should be:
>>
>>./build.sh svgrasterizer -a 0,0,612,792 text.svg
>>
>>   But since your image seems to be scaled somehow I
>>must assume
>>you are not using the default w/h for rendering.
>>
>>
>>
>>
> 
> ---------------------------------------------------------------------
> 
>>To unsubscribe, e-mail:
>>batik-users-unsubscribe@xml.apache.org
>>For additional commands, e-mail:
>>batik-users-help@xml.apache.org
>>
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> Exclusive Video Premiere - Britney Spears
> http://launch.yahoo.com/promos/britneyspears/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Rasterized Image Pixels not aligned with SVG Source

Posted by Guess Who <da...@yahoo.com>.
Yes actually there is a lot more to the story. I'm not
using the rasterizer, I'm using the transcoder. 

I am getting the rect width from the doc which is 612.

I need to scale the image down to 500 width so I get
the "scale factor" = 500/612 = .817

Then I transcode the image by using something like
this:

rectelementX = rect element's xcoord
rectelementY = rect element's ycoord
rectelementW = rect element's width
rectelementH = rect element's height

JPEGTranscoder trans = new JPEGTranscoder();
Rectangle aoi = new Rectangle(rectelementX,
                            rectelementY,
                            rectelementW,
                            rectelementH);

trans.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
new Float(.8));
trans.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new
Float(width*scaleFactor));
trans.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT,
new Float(height*scaleFactor));
trans.addTranscodingHint(JPEGTranscoder.KEY_AOI, aoi);

TranscoderInput input = new TranscoderInput(SVGDoc);
TranscoderOutput out = new TranscoderOutput(fos);

trans.transcode(input, out);

Now when I view the image in an applet using awt, I
capture some elementary mouse events.  When I place
the mouse pointer on the upper-leftmost corner of the
upper-leftmost text letter in the awt image, I get a Y
coord of about 61.  Now when we look at the svg code
the uppermost text is positioned at about 84 and with
the scaleFactor, it translates to about 69.  It is off
by  69-61 = 8 pixels. 

I think you are right and I am probably using the
transcoding process wrong, but I'm not sure what to
do... 

Thanks for your help with this.

--- Thomas DeWeese <Th...@Kodak.com> wrote:
> 
> Guess Who wrote:
> 
> David? :)
> 
> > I'm having a little trouble with images that were
> > transcoded with batik.  In particular, I'm working
> > with svg documents that contain almost all text
> > elements.  When the doc is transcoded into an
> image,
> > coords of the text that appears in the image don't
> > seem to correspond with the coords specified in
> the
> > svg doc. 
> > 
> > I've already taken into account the aspectratio in
> > testing the coords' congruency.  
> > 
> > Aspectratio = imgwidth/svg:aoiwidth
> 
>     Actually the proper name for this is the 'scale
> factor'.
> The Aspect ratio is typically the width/height (or
> vice versa).
> 
> > the aoi that i'm using is the rect element just
> inside
> > the page group.
> 
>    Well that is the same as the default area of the
> SVG
> so the scale factor here should be 1 (as is when I
> tested it).
> 
> > For instance, xcoord:image  = xcoord:svgdoc *
> > aspectratio
> > 
> > Correct me if I am wrong about the above calcs. 
> Here
> > is the svg doc...
> 
>    In the future using an attachment works much
> better as often
> things get munged by line-wrapping.  Also how are
> you generating
> the image?  When I use the svgrasterizer I get text
> exactly where
> I think it should be:
> 
> ./build.sh svgrasterizer -a 0,0,612,792 text.svg
> 
>    But since your image seems to be scaled somehow I
> must assume
> you are not using the default w/h for rendering.
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail:
> batik-users-help@xml.apache.org
> 


__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Rasterized Image Pixels not aligned with SVG Source

Posted by Thomas DeWeese <Th...@Kodak.com>.
Guess Who wrote:

David? :)

> I'm having a little trouble with images that were
> transcoded with batik.  In particular, I'm working
> with svg documents that contain almost all text
> elements.  When the doc is transcoded into an image,
> coords of the text that appears in the image don't
> seem to correspond with the coords specified in the
> svg doc. 
> 
> I've already taken into account the aspectratio in
> testing the coords' congruency.  
> 
> Aspectratio = imgwidth/svg:aoiwidth

    Actually the proper name for this is the 'scale factor'.
The Aspect ratio is typically the width/height (or vice versa).

> the aoi that i'm using is the rect element just inside
> the page group.

   Well that is the same as the default area of the SVG
so the scale factor here should be 1 (as is when I tested it).

> For instance, xcoord:image  = xcoord:svgdoc *
> aspectratio
> 
> Correct me if I am wrong about the above calcs.  Here
> is the svg doc...

   In the future using an attachment works much better as often
things get munged by line-wrapping.  Also how are you generating
the image?  When I use the svgrasterizer I get text exactly where
I think it should be:

./build.sh svgrasterizer -a 0,0,612,792 text.svg

   But since your image seems to be scaled somehow I must assume
you are not using the default w/h for rendering.



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org