001package com.hfg.svg.path; 002 003import java.awt.geom.Path2D; 004import java.awt.geom.Point2D; 005import java.util.List; 006 007//------------------------------------------------------------------------------ 008/** 009 * Object representation of an SVG (Scalable Vector Graphics) path vertical lineTo ('V' or 'v') command. 010 * 011 * @author J. Alex Taylor, hairyfatguy.com 012 */ 013//------------------------------------------------------------------------------ 014// com.hfg XML/HTML Coding Library 015// 016// This library is free software; you can redistribute it and/or 017// modify it under the terms of the GNU Lesser General Public 018// License as published by the Free Software Foundation; either 019// version 2.1 of the License, or (at your option) any later version. 020// 021// This library is distributed in the hope that it will be useful, 022// but WITHOUT ANY WARRANTY; without even the implied warranty of 023// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 024// Lesser General Public License for more details. 025// 026// You should have received a copy of the GNU Lesser General Public 027// License along with this library; if not, write to the Free Software 028// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 029// 030// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 031// jataylor@hairyfatguy.com 032//------------------------------------------------------------------------------ 033 034public class SvgPathVertLineToCmd extends SvgPathCmd 035{ 036 //--------------------------------------------------------------------------- 037 public SvgPathVertLineToCmd() 038 { 039 super('V'); 040 } 041 042 043 //--------------------------------------------------------------------------- 044 @Override 045 public SvgPathVertLineToCmd setRawNumbers(List<Float> inValue) 046 { 047 setNumSteps(inValue.size()); 048 049 super.setRawNumbers(inValue); 050 return this; 051 } 052 053 054 //-------------------------------------------------------------------------- 055 // From http://www.w3.org/TR/SVG/paths.html 056 // 057 // Draws a vertical line from the current point (cpx, cpy) to (cpx, y). 058 // V (uppercase) indicates that absolute coordinates will follow; v (lowercase) indicates that relative coordinates will follow. 059 // Multiple y values can be provided (although usually this doesn't make sense). At the end of the command, 060 // the new current point becomes (cpx, y) for the final value of y. 061 public Point2D.Float draw(Path2D.Float inPath) 062 { 063 List<Float> rawNumbers = getRawNumbers(); 064 int numIndex = 0; 065 066 Point2D.Float currentPoint = getStartingPoint(); 067 068 while (numIndex < rawNumbers.size()) 069 { 070 Point2D.Float point = new Point2D.Float((float) currentPoint.getX(), rawNumbers.get(numIndex++)); 071 072 if (isRelative()) 073 { 074 point.setLocation(point.getX(), point.getY() + currentPoint.getY()); 075 } 076 077 inPath.lineTo(point.getX(), point.getY()); 078 079 currentPoint = point; 080 } 081 082 // Return the last point. 083 return currentPoint; 084 } 085}