-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.1, 5.0
-
x86
-
windows_2000, windows_xp
Name: gm110360 Date: 12/03/2001
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
Printing and screen display yield different results when using PolyLine(int [],
int[],width, dash, dashphase); BasicStroke is used to create dashed, dot dashed
etc linestyles on a series of points in order to draw lines. Printing uses
PrinterJob (with pageable). Drawing uses g2d.draw(...);
Steps to reproduce:
create a panel which contains a JComponent. The JComponent will call method
to have an Object PointToPoint.java which will add points in arrays x and y for
a method call to our drawing utility.
Code:
//printing call
public int print( Graphics g, PageFormat pg, int i)
{
jg = new JGraphics((Graphics)g2d,1.0,this); //jgraphics just contains our
utilities but is a Graphics object
//some translation to get graphic aligned on pageformat etc.
trk.print(jg);
//more translations to accomodate > 1 page height graphics
}
// Jcomponet which points drawn on ie the trk
public void print( JGraphics g )
{
m_bPrinting = true;
m_Graphics = g;
RlrRectangle curRect = m_grid.getBoundingRect();
RlrRectangle rect = new RlrRectangle( curRect.getX(),
curRect.getY(),
curRect.width(), m_Owner.getGraphHeight() );
m_grid.setBoundingRect( rect );
// draw the grid
m_grid.Draw( m_Graphics );
m_grid.setBoundingRect( curRect );
Draw( g );
m_bPrinting = false;
}
public void Draw( JGraphics g )
{
// calculate the new baseline for drawing purposes
m_nBaseLine = g.RlrDistToLog( m_nLabelBoxHeight.multiply
(m_nNumberOfLabelBoxes) );
// draw the traces
TraceBase trace;
for( int k=0; k<m_traces.size(); k++ )
{
trace = (TraceBase)m_traces.elementAt(k);
if( m_bPrinting ) //true for printing only needed to
get entire range of points
trace.setRange( m_Owner.getPrintStart(),
m_Owner.getCurrMaxDepth() );
trace.Draw( g, true );
}
}
//point to point trace
public void drawtrace(graphics g, Vector drawpts){
//dash[]={2,2} or {10,5} or {10,5,2,5}
//dashphase starts at 0.0
if (drawPts.size() > 0)
{
int[] x = new int[drawPts.size()];
int[] y = new int[drawPts.size()];
int count = 0;
Point p;
for (int i = 0; i < drawPts.size(); i++)
{
p = (Point)drawPts.elementAt(i);
x[count] = ((Point)drawPts.elementAt(i)).x;
y[count] = ((Point)drawPts.elementAt(i)).y;
count++;
}
dashPhase = g.drawLine(x,y,count-1,m_thickness,dash, dashPhase);
}
//drawing utility note return value not used
public float drawLine(int[] x,int[] y, int count, int width,float[] dash,float
dash_phase)
{
float retPhase = 0;
if (m_Graphics instanceof Graphics2D)
{
Graphics2D graphics2D = (Graphics2D)m_Graphics;
Stroke origStroke = graphics2D.getStroke();
Stroke stroke = null;
if (dash == null)
{
stroke = new BasicStroke(width);
}
else
{
stroke = new BasicStroke(width,BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND,0,dash,dash_phase);
}
graphics2D.setStroke(stroke);
// using Line2D.Float instead of polyline will produce
different
// linestyles as desired .... graphics2D.draw(new Line2D.Float
(x1,y1,x2,y2));
//Line2D needs the retPhase value returned
graphics2D.drawPolyline(x, y, count);
graphics2D.setStroke(origStroke);
}
else
{ //used only if not Graphics2D
m_Graphics.drawPolyline(x,y,count);
}
return retPhase;
}
No Error message will occur but printing a line of points where the distance
between the two points is less than the linestyle stroke will show up as a
solid line in printing but not in the screen. Increasing the distance between
the points will show the line style in printing however. So it the distance
between the two points is 5 and the stroke dash is 5 or less ie.2 it will show
up as a dotted line in printing, but having a stroke dash > 5 it will show up
as a solid line.
(Review ID: 135228)
======================================================================
- duplicates
-
JDK-8041902 When printing, polylines are not rendered as joined
-
- Resolved
-