Other things to try would be STROKE_PURE and ANTIALIASING hints...
...jim
Russell East wrote:
Jim,
thanks for the clarification.
which release and platform is that on?
both 1.5.0_07-b03 and 1.6.0-rc-b89 on Fedora Linux, as well as 1.6.0-beta2-b85
on Windows XP
The context of this is that my "real" app is reading SVG and painting it using
java2D. The svg code looks like this:
<use xlink:href='a_path' fill='none' stroke='rgb(102,102,102)'
stroke-width='4' stroke-linecap='round' stroke-linejoin='round'/>
<use xlink:href='a_path' fill='none' stroke='rgb(255,255,255)'
stroke-dasharray='4,4' stroke-width='2' stroke-linecap='round'
stroke-linejoin='round'/>
so you can see the svg itself is supplying the "round" for line cap. I expect
that I will simply have to ignore it and use "butt" instead, or mess with the
supplied dash pattern.
Curiously enough, if I save one of these SVG drawings and re-display within
Firefox, it has the exact same problem.
-- Russell
--------------------------------------------------------------------------------
Jim Graham wrote:
The CAP decoration is applied at the end of each dash as documented (though
admittedly this phrase isn't repeated in the docs of the constructors, just
the class comments and the constants). Thus, the round caps will eat into the
null space of the dashes by half of the line width on both ends of each dash.
Square caps will also eat into the null voids of the dash pattern.
The net effect is that if you have a line width of 4 and a dash pattern of 4,4
and a CAP of:
BUTT - lines look 4,4 dashed
SQUARE - lines look continuous with no dashing
ROUND - lines connect, but "narrow" between the dashes
You are using a line width of 2 with the pattern of 4,4 and so the effect
isn't as pronounced as those examples, but it still makes it look like the
pattern has reduced null areas. The parts where it closes completely could be
the rendering code trying to do something sensible with a circular shape that
is only 2 pixels tall - which release and platform is that on?
In any case, try the different values for CAP and you should see the dash open
up or close more. If you then go back and modify your dash pattern to account
for the fact that the CAPs are eating into the null space of the pattern you
should be able to achieve the effect you are looking for.
Also, ROUND caps with a line width of 2 doesn't leave much room for
"roundness". That is probably responsible for most of the inconsistency you
see on the various angles. Try a line width of at least 3 for ROUND or use
BUTT instead...
...jim
Russell East wrote:
Hi,
the attached sample app uses Java2D dash pattern to try to create a
railway pattern, but the result isn't very good.
The code is specifying the dash array as { 4.0f, 4.0f } but I'm seeing
variable results:
o on the top line it seems more like {5, 3}
o on the left line seems more like { 6, 2, 5, 3 } and
o on the bottom line does not look dashed at all
Is it something I'm doing wrong in my code, or known problem?
-- Russell
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
------------------------------------------------------------------------
/*
* Copyright (C) 1999 - 2006 by Environmental Systems Research Institute Inc.
* All Rights Reserved.
*
* N O T I C E
*
* THIS MATERIAL IS CONSIDERED A TRADE SECRET BY ESRI.
* UNAUTHORIZED ACCESS IS PROHIBITED.
*
* $Workfile:$ $Revision:$
*/
package com.esri.mc.app;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;
/**
* dash lines look wrong
*/
public class RailwayLines extends JFrame {
public static void main(String[] args) {
new RailwayLines().setVisible(true);
}
public RailwayLines() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(200, 200, 500, 300);
String text = System.getProperty("java.vm.version");
this.setTitle(text);
MyCanvas canvas = new MyCanvas();
this.getContentPane().add(canvas);
}
}
final class MyCanvas extends JComponent {
private Stroke topStroke, backStroke;
private Color topColor, backColor;
private GeneralPath path;
MyCanvas() {
topStroke = constructTopStroke();
backStroke = constructBackStroke();
topColor = Color.WHITE;
backColor = new Color(102, 102, 102);
path = constructPath();
}
private GeneralPath constructPath() {
GeneralPath path = new GeneralPath();
path.moveTo(100.0f, 100.0f);
path.lineTo(200.0f, 200.0f);
path.lineTo(400.0f, 200.0f);
path.lineTo(400.0f, 100.0f);
path.closePath();
return path;
}
private Stroke constructBackStroke() {
float width = 4.0f;
int cap = BasicStroke.CAP_ROUND;
int join = BasicStroke.JOIN_ROUND;
return new BasicStroke(width, cap, join);
}
private Stroke constructTopStroke() {
float width = 2.0f;
int cap = BasicStroke.CAP_ROUND;
int join = BasicStroke.JOIN_ROUND;
float miterLimit = 10.f;
float[] dash = { 4.0f, 4.0f };
float dashPhase = 0.0f;
return new BasicStroke(width, cap, join, miterLimit, dash, dashPhase);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setColor(backColor);
g2.setStroke(backStroke);
g2.draw(path);
g2.setColor(topColor);
g2.setStroke(topStroke);
g2.draw(path);
}
}
=========================================================================== To
unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the
message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".