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 addPoint(int, int) and are memorized in a ordered list.
A stroke has also a width and a zoom level.

Version:
2013-01-04
Author:
andynaz

Nested Class Summary
private  class Stroke.Point
          A point.
 
Field Summary
private  List<Stroke.Point> lPoint
           
private  int width
           
private  float zoom
           
 
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.
 void setWidth(int width)
          Set the withd 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

lPoint

private List<Stroke.Point> lPoint

zoom

private float zoom

width

private int width
Constructor Detail

Stroke

public Stroke()
Create a stroke.

Method Detail

setWidth

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

Parameters:
width - the width of the stroke

setZoom

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

Parameters:
zoom - the zoom level of the stroke (must be 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)
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 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


(c) 2013 andynaz - http://andynaz.altervista.org