StringShape Alignment

This does not make sense…
Below is an image of drawing 3 strings using stringshape.
The left image is using CENTER align (which is the default)…
This looks exactly like I would expect (the [X] is the origin point)… and being slightly offset is understood as it is baseline aligned.

HOWEVER the 2nd image makes NO sense. LEFT ALIGNED… I would have expected each string to radiate out from the origin point, with the lower left corner of the first character cell being near the origin. As in “0” is “correct”… but both 90 and 45 are right shifted…

Can someone indicate if this is correct behaviour? and if so how does “LEFT ALIGN” apply in a way one can wrap their brain around it? (I have not even tried RIGHT Align yet)

Below is the code (rough I know) to reproduce the above image

  
  Dim s As StringShape
  Dim d As New Group2D
  
  g.ForeColor=&cffffff
  g.fillrect 0,0,g.Width,g.Height
  g.forecolor=&c000000
  
  //
  //  CENTER ALIGN
  //
  
  d=new Group2D
  
  s = New StringShape
  s.Text = "----90----"
  s.fillcolor=&c00ffff
  s.Rotation=3.141592/2
  s.HorizontalAlignment=StringShape.Alignment.Center
  s.VerticalAlignment=StringShape.Alignment.BaseLine
  s.scale=3
  d.Append(s)
  
  
  s = New StringShape
  s.Text = "----45----"
  s.fillcolor=&cff0000
  s.Rotation=3.141592/4
  s.HorizontalAlignment=StringShape.Alignment.Center
  s.VerticalAlignment=StringShape.Alignment.BaseLine
  s.scale=3
  d.Append(s)
  
  
  s = New StringShape
  s.Text = "----0^----"
  s.fillcolor=&c00ff00
  s.HorizontalAlignment=StringShape.Alignment.Center
  s.VerticalAlignment=StringShape.Alignment.BaseLine
  s.Rotation=0
  s.scale=3
  d.Append(s)
  g.drawobject d,150,150
  g.DrawRect 145,145,10,10
  g.drawline 145,145,155,155
  g.drawline 155,145,145,155
  //
  //  LEFT ALIGN
  //
  
  d=new Group2D
  
  s = New StringShape
  s.Text = "----90----"
  s.fillcolor=&c00ffff
  s.Rotation=3.141592/2
  s.HorizontalAlignment=StringShape.Alignment.Left
  s.VerticalAlignment=StringShape.Alignment.BaseLine
  s.scale=3
  d.Append(s)
  
  
  s = New StringShape
  s.Text = "----45----"
  s.fillcolor=&cff0000
  s.Rotation=3.141592/4
  s.HorizontalAlignment=StringShape.Alignment.Left
  s.VerticalAlignment=StringShape.Alignment.BaseLine
  s.scale=3
  d.Append(s)
  
  
  s = New StringShape
  s.Text = "----0^----"
  s.fillcolor=&c00ff00
  s.HorizontalAlignment=StringShape.Alignment.Left
  s.VerticalAlignment=StringShape.Alignment.BaseLine
  s.Rotation=0
  s.scale=3
  d.Append(s)
  
  g.drawobject d,350,150
  g.DrawRect 345,145,10,10
  g.drawline 345,145,355,155
  g.drawline 355,145,345,155

Does alignment make sense in this context?

If you want to rotate from the bottom left corner, it ‘feels’ as though the alignment must be left at all times.

Also curious to know if there is a difference when applying the alignment BEFORE the rotation, as opposed to afterwards as in your code?

Applying before or after makes no difference

and why do you think is makes no sense in this context? curious.

The objective is to rotate text
a) around a center point (this works… left side of image)
b) rotate text relative to a point… which is what I expected the right side to be. (PDF can do it :slight_smile: )

like this (manually edittied image)

I thought this world work … it’s closer but not quite right:

[code] s = New StringShape
s.Text = “----45----”
s.fillcolor=&cff0000
s.Rotation=3.141592/4
s.HorizontalAlignment=StringShape.Alignment.Left
s.x = - g.StringWidth(S.Text)/2.0
s.VerticalAlignment=StringShape.Alignment.BaseLine
s.scale=3
d.Append(s)

s = New StringShape
s.Text = “----0^----”
s.fillcolor=&c00ff00
s.VerticalAlignment=StringShape.Alignment.BaseLine
s.HorizontalAlignment=StringShape.Alignment.Left
s.x = - g.StringWidth(S.Text)/2.0
s.Rotation=0
s.scale=3
d.Append(s)

g.drawobject d,350,150
g.DrawRect 345,145,10,10
g.drawline 345,145,355,155
g.drawline 355,145,345,155[/code]

Basically because what you want is for the text to start rendering at the x, y location.
That suggests to me that it is ‘left aligned to that point’.

I think my problem is with the concept of alignment of a string shape at all.

A stringshape is placed according to the x,y properties.
These are by definition the centres of the string’s baseline.

Left right or centre aligned, if the x is the centre of the string, I can’t see how ‘horizontal alignment’ makes any difference
The x is still the centre, isn’t it?
So the text is centre aligned around the x

Actually it is not a matter of what I want or don’t want…

The question is WHY does it act the way it does…

I have an app (PDF class discussed in another thread) that needs to replicate the results…
I have it doing so… but the results don’t make sense.

I agree… that that is the default …
LEFT ALIGNED I would reasonable think would move the “center point” to the left end of the strings baseline (which in my opinion would result in my second image)

So I don’t need ways to make Graphics.Stringshape work the way I want it to… just an explanation as to why it works the way that it does (which I find counter-intutivie)

Note that ZERO DEGREES DOES work the way I think it should… the others are offset along the X-axis by (cos(a)*stringwidth(s))/2 I think

[quote]Actually it is not a matter of what I want or don’t want…
The question is WHY does it act the way it does…[/quote]

Fair enough.

Best guess:
It takes the string, rotates it around the ‘normal’ x,y co-ordinates.
Determines the bounding rectangle
Then left aligns the entire rectangle by moving the whole along the x axis.

which may well equate to >>offset along the X-axis by (cos(a)*stringwidth(s))/2<<

Well I have made an executive decision :slight_smile:

My PDF class will use StringShape Alignment properties in what I consider to be the most intuitive manner

That is Left will align the left of the string to the origin point, and rotate the end around that (see 2nd diagram above)
Center will do exactly what it is doing now… Rotate the text around the center of the string
Right will be the opposite of left (duh)… and insure the RIGHT side of the string touchs the origin point (+/- baseline of course)

So you’re saying, Dave, that Xojo graphics and your PDF Class will give different results in such cases?

That is what I am saying… I spent the better part of the afternoon… trying to duplicate whatever it is that Xojo is doing when you set Alignment to anything other than CENTER… And the results are a) counterintuitive at best… and b) not reproducable.

Look at the first diagram. How does one attribute the concept of LEFTALIGNMENT to that image? I mean everything is to the RIGHT by some transformed value. To me, the diagram in the second post is MUCH more useful

As of right now, this is the only place where my class varies from what XOJO Graphics object does.