User Tools

Site Tools


pdf:transformationexamples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
pdf:transformationexamples [2015/03/31 12:32] – created christianpdf:transformationexamples [2015/04/02 18:07] – [flip vertically and located origin in upper left corner] christian
Line 1: Line 1:
 +====== Coordinate Transformations ======
 +
 By default, PDF uses a conventional graph coordinate system, with the origin in the lower left corner. These examples create a 200x200 page with the origin in the middle, a vertical line at x=0, a horizontal lines at y = 0 and text in each quadrant. By default, PDF uses a conventional graph coordinate system, with the origin in the lower left corner. These examples create a 200x200 page with the origin in the middle, a vertical line at x=0, a horizontal lines at y = 0 and text in each quadrant.
  
-The code is integrated as +
- PDF.Document demo10_transformationsNone. +
- PDF.Document demo10a_transformationsFlipVertically. +
- PDF.Document demo10b_transformationsFlipHorizontally. +
- PDF.Document demo10c_transformationsFlipDiagonal. +
- PDF.Document demo10d_transformationsFlipVerticallyTranslateOrigin.+
  
 ===== no transformation ===== ===== no transformation =====
  
- page := Graphics.PDF.Page +<code smalltalk> 
- newInBounds: (-100 @ -100 corner: 100 @ 100) +page := Graphics.PDF.Page 
- colorspace: DeviceRGB new +  newInBounds: (-100 @ -100 corner: 100 @ 100) 
- render: [:renderer ¦ +  colorspace: DeviceRGB new 
- renderer moveTo: -100 @ 0; lineTo: 100 @ 0; stroke.  "line at y = 0" +  render: [:renderer ¦ 
- renderer moveTo: 0 @ -100; lineTo: 0 @ 100; stroke.  "line at x = 0" +    renderer moveTo: -100 @ 0; lineTo: 100 @ 0; stroke.  "line at y = 0" 
- renderer textObjectDo:+    renderer moveTo: 0 @ -100; lineTo: 0 @ 100; stroke.  "line at x = 0" 
- renderer setFont: #Helvetica size: 1. +    renderer textObjectDo:
- renderer textMatrix: #(4 0 0 4 50 50); showString: '(50 50)'+      renderer setFont: #Helvetica size: 1. 
- renderer textMatrix: #(2 0 0 2 -50 50); showString: '(-50 50)'+      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)']]. +      renderer textMatrix: #(2 0 0 2 50 -50); showString: '(50 -50)'
- page saveAndShowAs: 'demo10_transformationsNone.pdf'+      renderer textMatrix: #(2 0 0 2 -50 -50); showString: '(-50 -50)']]. 
 +page saveAndShowAs: 'demo10_transformationsNone.pdf' 
 +</code> 
 + 
 +{{demo10_transformationsnone.pdf}}
  
 ===== flip vertically ===== ===== flip vertically =====
  
- "x -> x  ,  y -> -y   +**x -> x  ,  y -> -y** 
- In this example the matrix is coded manually.  + 
- It can also be coded as 'Matrix scale: 4 @ -4to get '[4 0 0 -4 0 0]'  +In this example the matrix is coded manually.  
- and '(Matrix scale: 4 @ -4) translate: 50 @ 50to get '[4 0 0 -4 50 50]'" +It can also be coded as <code smalltalk>Matrix scale: 4 @ -4</code> to get ''[4 0 0 -4 0 0]''  
- page := Graphics.PDF.Page +and <code smalltalk>(Matrix scale: 4 @ -4) translate: 50 @ 50</code> to get ''[4 0 0 -4 50 50]''" 
- newInBounds: (-100 @ -100 corner: 100 @ 100) + 
- colorspace: DeviceRGB new +<code smalltalk> 
- render: [:renderer ¦ +page := Graphics.PDF.Page 
- renderer concat: (Matrix scale: 1 @ -1). +  newInBounds: (-100 @ -100 corner: 100 @ 100) 
- renderer moveTo: -100 @ 0; lineTo: 100 @ 0; stroke.  "line at y = 0" +  colorspace: DeviceRGB new 
- renderer moveTo: 0 @ -100; lineTo: 0 @ 100; stroke.  "line at x = 0" +  render: [:renderer ¦ 
- renderer textObjectDo:+    renderer concat: (Matrix scale: 1 @ -1). 
- renderer setFont: #Helvetica size: 1. +    renderer moveTo: -100 @ 0; lineTo: 100 @ 0; stroke.  "line at y = 0" 
- renderer textMatrix: #(4 0 0 -4 50 50); showString: '(50 50)'+    renderer moveTo: 0 @ -100; lineTo: 0 @ 100; stroke.  "line at x = 0" 
- renderer textMatrix: #(2 0 0 -2 -50 50); showString: '(-50 50)'+    renderer textObjectDo:
- renderer textMatrix: #(2 0 0 -2 50 -50); showString: '(50 -50)'+      renderer setFont: #Helvetica size: 1. 
- renderer textMatrix: #(2 0 0 -2 -50 -50); showString: '(-50 -50)']]. +      renderer textMatrix: #(4 0 0 -4 50 50); showString: '(50 50)'
- page saveAndShowAs: 'demo10a_transformationsFlipVertically.pdf'+      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' 
 +</code>
  
 +{{demo10a_transformationsflipvertically.pdf}}
 ===== flip horizontally ===== ===== flip horizontally =====
  
Line 62: Line 68:
  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'  page saveAndShowAs: 'demo10b_transformationsFlipHorizontally.pdf'
 +
 +{{demo10b_transformationsfliphorizontally.pdf}}
  
 ===== flip diagonally ===== ===== flip diagonally =====
Line 80: Line 88:
  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'  page saveAndShowAs: 'demo10c_transformationsFlipDiagonal.pdf'
 +
 +{{demo10c_transformationsflipdiagonal.pdf}}
  
 ===== flip vertically and located origin in upper left corner ===== ===== flip vertically and located origin in upper left corner =====
Line 100: Line 110:
  renderer textMatrix: #(2 0 0 -2 20 40); showString: '(20 40)']].  renderer textMatrix: #(2 0 0 -2 20 40); showString: '(20 40)']].
  page saveAndShowAs: 'demo10d_transformationsFlipVerticallyTranslateOrigin.pdf'  page saveAndShowAs: 'demo10d_transformationsFlipVerticallyTranslateOrigin.pdf'
 +
 +{{demo10d_transformationsflipverticallytranslateorigin.pdf}}
/var/www/virtual/code4hl/html/dokuwiki/data/pages/pdf/transformationexamples.txt · Last modified: 2015/04/02 18:12 by christian