pdf:transformationexamples
Table of Contents
Coordinate Transformations
By default, PDF uses a conventional graph coordinate system, with the origin in the lower left corner. These examples create a 200×200 page with the origin in the middle, a vertical line at x=0, a horizontal lines at y = 0 and text in each quadrant.
no transformation
page := Graphics.PDF.Page newInBounds: (-100 @ -100 corner: 100 @ 100) colorspace: DeviceRGB new render: [:renderer ¦ renderer moveTo: -100 @ 0; lineTo: 100 @ 0; stroke. "line at y = 0" renderer moveTo: 0 @ -100; lineTo: 0 @ 100; stroke. "line at x = 0" renderer textObjectDo: [ renderer setFont: #Helvetica size: 1. renderer textMatrix: #(4 0 0 4 50 50); showString: '(50 50)'. renderer textMatrix: #(2 0 0 2 -50 50); showString: '(-50 50)'. renderer textMatrix: #(2 0 0 2 50 -50); showString: '(50 -50)'. renderer textMatrix: #(2 0 0 2 -50 -50); showString: '(-50 -50)']]. page saveAndShowAs: 'demo10_transformationsNone.pdf'
flip vertically
"x -> x , y -> -y In this example the matrix is coded manually. It can also be coded as Matrix scale: 4 @ -4 to get '[4 0 0 -4 0 0]' and (Matrix scale: 4 @ -4) translate: 50 @ 50 to get '[4 0 0 -4 50 50]'" page := Graphics.PDF.Page newInBounds: (-100 @ -100 corner: 100 @ 100) colorspace: DeviceRGB new render: [:renderer ¦ renderer concat: (Matrix scale: 1 @ -1). renderer moveTo: -100 @ 0; lineTo: 100 @ 0; stroke. "line at y = 0" renderer moveTo: 0 @ -100; lineTo: 0 @ 100; stroke. "line at x = 0" renderer textObjectDo: [ renderer setFont: #Helvetica size: 1. renderer textMatrix: #(4 0 0 -4 50 50); showString: '(50 50)'. renderer textMatrix: #(2 0 0 -2 -50 50); showString: '(-50 50)'. renderer textMatrix: #(2 0 0 -2 50 -50); showString: '(50 -50)'. renderer textMatrix: #(2 0 0 -2 -50 -50); showString: '(-50 -50)']]. page saveAndShowAs: 'demo10a_transformationsFlipVertically.pdf'
flip horizontally
"x -> -x , y -> y" page := Graphics.PDF.Page newInBounds: (-100 @ -100 corner: 100 @ 100) colorspace: DeviceRGB new render: [:renderer ¦ renderer concat: (Matrix scale: -1 @ 1). renderer moveTo: -100 @ 0; lineTo: 100 @ 0; stroke. "line at y = 0" renderer moveTo: 0 @ -100; lineTo: 0 @ 100; stroke. "line at x = 0" renderer textObjectDo: [ renderer setFont: #Helvetica size: 1. renderer textMatrix: #(-4 0 0 4 50 50); showString: '(50 50)'. renderer textMatrix: #(-2 0 0 2 -50 50); showString: '(-50 50)'. renderer textMatrix: #(-2 0 0 2 50 -50); showString: '(50 -50)'. renderer textMatrix: #(-2 0 0 2 -50 -50); showString: '(-50 -50)']]. page saveAndShowAs: 'demo10b_transformationsFlipHorizontally.pdf'
flip diagonally
"x -> -x , y -> -y" page := Graphics.PDF.Page newInBounds: (-100 @ -100 corner: 100 @ 100) colorspace: DeviceRGB new render: [:renderer ¦ renderer concat: (Matrix scale: -1 @ -1). renderer moveTo: -100 @ 0; lineTo: 100 @ 0; stroke. "line at y = 0" renderer moveTo: 0 @ -100; lineTo: 0 @ 100; stroke. "line at x = 0" renderer textObjectDo: [ renderer setFont: #Helvetica size: 1. renderer textMatrix: #(-4 0 0 -4 50 50); showString: '(50 50)'. renderer textMatrix: #(-2 0 0 -2 -50 50); showString: '(-50 50)'. renderer textMatrix: #(-2 0 0 -2 50 -50); showString: '(50 -50)'. renderer textMatrix: #(-2 0 0 -2 -50 -50); showString: '(-50 -50)']]. page saveAndShowAs: 'demo10c_transformationsFlipDiagonal.pdf'
flip vertically and located origin in upper left corner
"This is the more common layout used for reports" page := Graphics.PDF.Page newInBounds: (0 @ 0 corner: 100 @ -100) colorspace: DeviceRGB new render: [:renderer ¦ renderer concat: (Matrix scale: 1 @ -1). renderer textObjectDo: [ renderer setFont: #Helvetica size: 1. renderer textMatrix: #(2 0 0 -2 10 10); showString: '(10 10)'. renderer textMatrix: #(2 0 0 -2 10 20); showString: '(10 20)'. renderer textMatrix: #(2 0 0 -2 10 30); showString: '(10 30)'. renderer textMatrix: #(2 0 0 -2 10 40); showString: '(10 40)'. renderer textMatrix: #(2 0 0 -2 20 10); showString: '(20 10)'. renderer textMatrix: #(2 0 0 -2 20 20); showString: '(20 20)'. renderer textMatrix: #(2 0 0 -2 20 30); showString: '(20 30)'. renderer textMatrix: #(2 0 0 -2 20 40); showString: '(20 40)']]. page saveAndShowAs: 'demo10d_transformationsFlipVerticallyTranslateOrigin.pdf'
/var/www/virtual/code4hl/html/dokuwiki/data/pages/pdf/transformationexamples.txt · Last modified: 2015/04/02 18:12 by christian