Lisp HUG Maillist Archive

Printing rotated text

Hello list,

I have a need to print some text rotated 90degrees counterclockwise.

Using this code, nothing is printed. The text is off the viewable page.

(defun print1-demo ()
   (let ((printer (capi:current-printer)))

     (capi:with-print-job (port :printer printer)
      (format t "transform pre-rotation ~A~%" 
(gp:graphics-port-transform port))
       (gp:with-graphics-rotation (port 1.5707963)  ;pi over 2 radians
           (format t "transform with rotation ~A~%" 
(gp:graphics-port-transform port))
           (gp:draw-string port "Hello World!" 10 250
              :font (gp:find-best-font port (gp:make-font-description 
:family "Arial" :size 10 :weight :bold))
              :foreground :black)))))

The text output is:
transform pre-rotation (1 0 0 1 0 0)
transform with rotation (7.54979E-8 1.0 -1.0 7.54979E-8 0.0 0.0)

Why are the transform numbers such as they are?
I know it is using the origin 0,0 as the point for rotation which is why 
its rotating off the page.
What will translate back into view vertically along the left edge?
My preference is to use the point of rotation to be close to what is 
used in draw-string.

Thank you,

Ron Lund


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html

Re: Printing rotated text

I'm not familiar with the specific notation but at a high level what you're going to need to do is translate it (* width-char num-char) along the Y axis.

I don't believe Arial is a fixed width font though so if you want to get it right up to the upper left hand corner you're going to want to look up the exact width of each character in your sting and add all of those together. Quick and dirty is just to take the max width and multiply it by the number of characters. It'll be close so long as your sting is relatively short.

On Thu, Jun 7, 2018 at 3:07 PM Ron Lund <rlund@secureoutcomes.net> wrote:
Hello list,

I have a need to print some text rotated 90degrees counterclockwise.

Using this code, nothing is printed. The text is off the viewable page.

(defun print1-demo ()
   (let ((printer (capi:current-printer)))

     (capi:with-print-job (port :printer printer)
      (format t "transform pre-rotation ~A~%"
(gp:graphics-port-transform port))
       (gp:with-graphics-rotation (port 1.5707963)  ;pi over 2 radians
           (format t "transform with rotation ~A~%"
(gp:graphics-port-transform port))
           (gp:draw-string port "Hello World!" 10 250
              :font (gp:find-best-font port (gp:make-font-description
:family "Arial" :size 10 :weight :bold))
              :foreground :black)))))

The text output is:
transform pre-rotation (1 0 0 1 0 0)
transform with rotation (7.54979E-8 1.0 -1.0 7.54979E-8 0.0 0.0)

Why are the transform numbers such as they are?
I know it is using the origin 0,0 as the point for rotation which is why
its rotating off the page.
What will translate back into view vertically along the left edge?
My preference is to use the point of rotation to be close to what is
used in draw-string.

Thank you,

Ron Lund


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html
--
The only path here was the one you walked.

Re: Printing rotated text

If you want to rotate with 10,250 as the center point, then you need to
translate before and after the rotation:

(gp:with-graphics-translation (port 10 250)
   (gp:with-graphics-rotation (port 1.5707963)  ;pi over 2 radians
     (gp:with-graphics-translation (port -10 -250)
       (gp:draw-string port "Hello World!" 10 250
                       :font (gp:find-best-font port (gp:make-font-description :family "Arial" :size 10 :weight :bold))
                       :foreground :black))))

-- 
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/

>>>>> On Thu, 7 Jun 2018 15:04:43 -0600, Ron Lund said:
> 
> Hello list,
> 
> I have a need to print some text rotated 90degrees counterclockwise.
> 
> Using this code, nothing is printed. The text is off the viewable page.
> 
> (defun print1-demo ()
>    (let ((printer (capi:current-printer)))
> 
>      (capi:with-print-job (port :printer printer)
>       (format t "transform pre-rotation ~A~%" 
> (gp:graphics-port-transform port))
>        (gp:with-graphics-rotation (port 1.5707963)  ;pi over 2 radians
>            (format t "transform with rotation ~A~%" 
> (gp:graphics-port-transform port))
>            (gp:draw-string port "Hello World!" 10 250
>               :font (gp:find-best-font port (gp:make-font-description 
> :family "Arial" :size 10 :weight :bold))
>               :foreground :black)))))
> 
> The text output is:
> transform pre-rotation (1 0 0 1 0 0)
> transform with rotation (7.54979E-8 1.0 -1.0 7.54979E-8 0.0 0.0)
> 
> Why are the transform numbers such as they are?
> I know it is using the origin 0,0 as the point for rotation which is why 
> its rotating off the page.
> What will translate back into view vertically along the left edge?
> My preference is to use the point of rotation to be close to what is 
> used in draw-string.
> 
> Thank you,
> 
> Ron Lund
> 
> 
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> lisp-hug@lispworks.com
> http://www.lispworks.com/support/lisp-hug.html
> 

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html

Re: Printing rotated text

Thank you Rob.

I was working along that thinking.
Without doing that calculation I just started trying numbers.
The main learning is that the point of origin is the only thing that is rotated.
The text is still printed horizontally at the new rotated point.

So, I will need to draw the text on a pixmap and then rotate this
to have the text to display vertically.

Ron

On 6/7/2018 3:35 PM, Rob Seger wrote:
I'm not familiar with the specific notation but at a high level what you're going to need to do is translate it (* width-char num-char) along the Y axis.

I don't believe Arial is a fixed width font though so if you want to get it right up to the upper left hand corner you're going to want to look up the exact width of each character in your sting and add all of those together. Quick and dirty is just to take the max width and multiply it by the number of characters. It'll be close so long as your sting is relatively short.

On Thu, Jun 7, 2018 at 3:07 PM Ron Lund <rlund@secureoutcomes.net> wrote:
Hello list,

I have a need to print some text rotated 90degrees counterclockwise.

Using this code, nothing is printed. The text is off the viewable page.

(defun print1-demo ()
   (let ((printer (capi:current-printer)))

     (capi:with-print-job (port :printer printer)
      (format t "transform pre-rotation ~A~%"
(gp:graphics-port-transform port))
       (gp:with-graphics-rotation (port 1.5707963)  ;pi over 2 radians
           (format t "transform with rotation ~A~%"
(gp:graphics-port-transform port))
           (gp:draw-string port "Hello World!" 10 250
              :font (gp:find-best-font port (gp:make-font-description
:family "Arial" :size 10 :weight :bold))
              :foreground :black)))))

The text output is:
transform pre-rotation (1 0 0 1 0 0)
transform with rotation (7.54979E-8 1.0 -1.0 7.54979E-8 0.0 0.0)

Why are the transform numbers such as they are?
I know it is using the origin 0,0 as the point for rotation which is why
its rotating off the page.
What will translate back into view vertically along the left edge?
My preference is to use the point of rotation to be close to what is
used in draw-string.

Thank you,

Ron Lund


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html
--
The only path here was the one you walked.

Updated at: 2020-12-10 08:29 UTC