writeLine(mPDFGeometryWriter, mCoordinateDecimal.format(x) + " " + mCoordinateDecimal.format(y) + " Td");
int j = 0, index = -1; while (j < PDF_FONTS.length && index < 0) { if (PDF_FONTS[j].equals(mFontName)) index = j; else j++; } if (index < 0) { index = 4; } writeLine(mPDFGeometryWriter, "/F" + index + " " + mCoordinateDecimal.format(mFontSize) + " Tf"); if (mFontOutlineWidth > 0) { writeLine(mPDFGeometryWriter, "1 Tr " + mCoordinateDecimal.format(mFontOutlineWidth) + " w"); } else { writeLine(mPDFGeometryWriter, "0 Tr"); }
	public void label(ArrayList pointList, String label)	{		Point2D pt, startPt;		double x, y;		String nextLine;		StringTokenizer st;		int lineNumber;		AffineTransform affine;		FontRenderContext frc = null;		Stroke originalStroke = null;		if (mOutputType != POSTSCRIPT_GEOMETRY && mOutputType != PDF)		{			frc = mGraphics2D.getFontRenderContext();						if (mFontOutlineWidth > 0)			{				/*				 * Save existing linestyle and create new one for drawing outlines of each letter.				 */				originalStroke = mGraphics2D.getStroke();				BasicStroke outlineStroke = new BasicStroke((float)mFontOutlineWidth,					BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2.0f);				mGraphics2D.setStroke(outlineStroke);			}		}		/*		 * Draw label at each position in list.		 */		for (int i = 0; i < pointList.size(); i++)		{			pt = (Point2D)(pointList.get(i));			x = pt.getX();			y = pt.getY();			if (mOutputType == PDF)			{				writeLine(mPDFGeometryWriter, "BT");				writeLine(mPDFGeometryWriter, mCoordinateDecimal.format(x) + " " +					mCoordinateDecimal.format(y) + " Td");			}			/*			 * Draw each line of label below the one above.			 */			st = new StringTokenizer(label, Constants.LINE_SEPARATOR);			lineNumber = 0;			while (st.hasMoreTokens())			{				nextLine = st.nextToken();				if (mOutputType == POSTSCRIPT_GEOMETRY)				{					writeLine(mWriter, mCoordinateDecimal.format(x) + " " +						mCoordinateDecimal.format(y) + " m");					/*					 * Pass counter and line to PostScript procedure for					 * drawing each line of the label.					 */					writeLine(mWriter, Integer.toString(lineNumber));					writePostScriptString(mWriter, nextLine);					writeLine(mWriter, "t");				}				else if (mOutputType == PDF)				{					/*					 * Draw each line of the label to PDF file.					 */					writePostScriptString(mPDFGeometryWriter, nextLine);					writeLine(mPDFGeometryWriter, "Tj T*");				}				else if (mOutputType == SVG)				{					double yInc = 0;					if (lineNumber > 0)					{						Rectangle2D bounds = mBaseFont.getStringBounds(nextLine, frc);						yInc = bounds.getHeight() * lineNumber;					}					String anchor;					if (mJustificationShiftX == -1)						anchor = "end";					else if (mJustificationShiftX == 0)						anchor = "start";					else						anchor = "middle";					Color color = mGraphics2D.getColor();					int alpha = color.getAlpha();					Font font = mGraphics2D.getFont();					StringBuffer extras = new StringBuffer();					if (font.isBold())						extras.append(" font-weight=\"bold\" ");					if (font.isItalic())						extras.append(" font-style=\"italic\" ");					if (mFontOutlineWidth > 0)					{						extras.append(" stroke=\"");						extras.append(ColorDatabase.toHexString(color));						extras.append("\" stroke-width=\"");						extras.append(mFontOutlineWidth);						extras.append("\" ");						if (alpha != 255)						{							extras.append(" stroke-opacity=\"");							extras.append(alpha / 255.0f);							extras.append("\" ");						}					}					else					{						extras.append(" fill=\"");						extras.append(ColorDatabase.toHexString(color));						extras.append("\" ");						if (alpha != 255)						{							extras.append(" fill-opacity=\"");							extras.append(alpha / 255.0f);							extras.append("\" ");						}					}					if (mIsClipPathActive)					{						extras.append(" clip-path=\"url(#clip");						extras.append(mClipPathCounter);						extras.append(")\" ");					}					double px, py;					if (mFontRotation != 0)					{						/*						 * Rotate text around origin point.						 * Rotation is negative sense because Y axis						 * decreases downwards.						 */						writeLine(mWriter, "<g transform=\"translate(" +							mCoordinateDecimal.format(x) + ", " +							mCoordinateDecimal.format(mPageHeight - y) +							") rotate(" +							mCoordinateDecimal.format(Math.toDegrees(-mFontRotation)) +							")\">");						px = py = 0;					}					else					{						px = x;						py = mPageHeight - (y - yInc);					}					/*					 * Shift text to correct vertical alignment.					 */					py -= mJustificationShiftY * font.getSize2D();										writeLine(mWriter, "<text x=\"" + mCoordinateDecimal.format(px) +						"\" y=\"" + mCoordinateDecimal.format(py) +						"\" text-anchor=\"" + anchor + "\"");					String fontName = font.getName();					/*					 * Change default Java font names to something sensible.					 */					if (fontName.equalsIgnoreCase("sansserif") ||						fontName.equalsIgnoreCase("dialog"))					{						fontName = "Courier";					}					writeLine(mWriter, "  font-family=\"" + fontName + "\" " +						"font-size=\"" + font.getSize2D() + "\" " +						extras.toString());					/*					 * Make text string XML safe.					 */					nextLine = nextLine.replaceAll("&", "&amp;");					nextLine = nextLine.replaceAll("<", "&lt;");					nextLine = nextLine.replaceAll(">", "&gt;");					nextLine = nextLine.replaceAll("\"", "&quot;");					writeLine(mWriter, ">" + nextLine + "</text>");					if (mFontRotation != 0)						writeLine(mWriter, "</g>");				}				else				{					/*					 * Reposition label from original point so it has correct justification.					 */					if (mJustificationShiftX != 0.0 || mJustificationShiftY != 0.0 || lineNumber > 0)					{						Rectangle2D bounds = mBaseFont.getStringBounds(nextLine, frc);						affine = AffineTransform.getTranslateInstance(x, y);						affine.rotate(mFontRotation);	   					startPt = new Point2D.Double(bounds.getWidth() * mJustificationShiftX,	   						bounds.getHeight() * (mJustificationShiftY - lineNumber));	   					affine.transform(startPt, startPt);					}					else					{						startPt = pt;					}										float fx = (float)startPt.getX();					float fy = (float)startPt.getY();										if (mFontOutlineWidth > 0)					{						/*						 * Draw only outline of letters in label as lines.						 */						GlyphVector glyphs = mGraphics2D.getFont().createGlyphVector(frc, nextLine);						Shape outline = glyphs.getOutline(fx, fy);												mGraphics2D.draw(outline);											}					else					{						/*						 * Draw plain label.						 */						mGraphics2D.drawString(nextLine, fx, fy);					}				}				lineNumber++;			}						if (mOutputType == PDF)				writeLine(mPDFGeometryWriter, "ET");		}		if (originalStroke != null)		{			/*			 * Restore line style.			 */			mGraphics2D.setStroke(originalStroke);		}	}