iRex DR1000 Merger v0.4.1

it.andynaz.irex.dr1000.scribble
Class Stroke

java.lang.Object
  extended by it.andynaz.irex.dr1000.scribble.Stroke

public class Stroke
extends Object

A stroke. A stroke is made up of various points. Points can be added via the addPoint(int, int) method and are memorized in a ordered list.
A stroke has also a width and a zoom level.

Version:
2013-08-01
Author:
andynaz

Nested Class Summary
private  class Stroke.Point
          A point.
 
Field Summary
private  List<Stroke.Point> points
          List of points.
private  int width
          Width.
private  float zoom
          Zoom level.
 
Constructor Summary
Stroke()
          Create a stroke.
 
Method Summary
 void addPoint(int x, int y)
          Add a point to this stroke.
(package private)  void draw(com.lowagie.text.pdf.PdfContentByte cb, float xAdjust, float yAdjust)
          Draw the stroke, using the default color for the strokes (as specified in the ColorMgr class).
(package private)  void draw(com.lowagie.text.pdf.PdfContentByte cb, float xAdjust, float yAdjust, Color c)
          Draw the stroke.
 void setWidth(int width)
          Set the width of this stroke.
 void setZoom(float zoom)
          Set the zoom level of this stroke.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

points

private List<Stroke.Point> points
List of points.


zoom

private float zoom
Zoom level.


width

private int width
Width.

Constructor Detail

Stroke

public Stroke()
Create a stroke.

Method Detail

setWidth

public void setWidth(int width)
Set the width of this stroke.

Parameters:
width - the width of the stroke (must be positive)
Throws:
IllegalArgumentException - if width is not positive

setZoom

public void setZoom(float zoom)
Set the zoom level of this stroke.

Parameters:
zoom - the zoom level of the stroke (must be positive)
Throws:
IllegalArgumentException - if zoom is not positive

addPoint

public void addPoint(int x,
                     int y)
Add a point to this stroke. the point is specified with its coordinates.

Parameters:
x - 'x' coordinate of the point to add
y - 'y' coordinate of the point to add

draw

void draw(com.lowagie.text.pdf.PdfContentByte cb,
          float xAdjust,
          float yAdjust,
          Color c)
Draw the stroke.

When being drawn on the PDF, all the points of the stroke are scaled and adapted for the iText library, which uses a different coordinate system as the one used by the iPDF library, as shown in the following picture.

At first are scaled with the zoom factor using (as explained here) the formulas

          x                1            48 x
 x' = ---------- * ----------------- = ------
       zoom/100     160/72 (1-1/16)     zoom
 
          y                1            48 y
 y' = ---------- * ----------------- = ------
       zoom/100     160/72 (1-1/16)     zoom
 
so the zoom factor has to be set with the setZoom(float) method before calling the draw(com.lowagie.text.pdf.PdfContentByte, float, float) method).
After scaling, the coordinates are converted to the itext coordinates system using the formulas
 x' = xa + x
 
 y' = ya - y
 
where xa and ya are the arguments of the method.

Parameters:
cb - content of the PDF
xAdjust - value to correct the 'x' coordinate of all the points in this stroke
yAdjust - value to correct the 'y' coordinate of all the points in this stroke
Throws:
ArithmeticException - if the setZoom(float)} method has not been called

draw

void draw(com.lowagie.text.pdf.PdfContentByte cb,
          float xAdjust,
          float yAdjust)
Draw the stroke, using the default color for the strokes (as specified in the ColorMgr class).

Parameters:
cb - content of the PDF
xAdjust - value to correct the 'x' coordinate of all the points in this stroke
yAdjust - value to correct the 'y' coordinate of all the points in this stroke
Throws:
ArithmeticException - if the setZoom(float)} method has not been called
See Also:
draw(com.lowagie.text.pdf.PdfContentByte, float, float, java.awt.Color)

iRex DR1000 Merger v0.4.1

© 2013 andynaz - http://andynaz.altervista.org