/** * Outputs a {@code float} directly to the content. * * @param n the {@code float} * @return current canvas. */ public PdfCanvas writeLiteral(float n) { contentStream.getOutputStream().writeFloat(n); return this; }
/** * Replaces the text matrix. Contrast with {@link PdfCanvas#concatMatrix} * * @param a operand 1,1 in the matrix. * @param b operand 1,2 in the matrix. * @param c operand 2,1 in the matrix. * @param d operand 2,2 in the matrix. * @param x operand 3,1 in the matrix. * @param y operand 3,2 in the matrix. * @return current canvas. */ public PdfCanvas setTextMatrix(float a, float b, float c, float d, float x, float y) { contentStream.getOutputStream() .writeFloat(a) .writeSpace() .writeFloat(b) .writeSpace() .writeFloat(c) .writeSpace() .writeFloat(d) .writeSpace() .writeFloat(x) .writeSpace() .writeFloat(y).writeSpace() .writeBytes(Tm); return this; } /**
.writeFloat(wx) .writeSpace() .writeFloat(0)//wy .writeSpace() .writeBytes(d0); } else { contentStream.getOutputStream() .writeFloat(wx) .writeSpace() .writeFloat(0)//wy .writeSpace() .writeFloat(llx) .writeSpace() .writeFloat(lly) .writeSpace() .writeFloat(urx) .writeSpace() .writeFloat(ury) .writeSpace() .writeBytes(d1);
/** * Moves to the start of the next line, offset from the start of the current line. * <br> * As a side effect, this sets the leading parameter in the text state. * <br> * * @param x offset of the new current point * @param y y-coordinate of the new current point * @return current canvas. */ public PdfCanvas moveTextWithLeading(float x, float y) { currentGs.setLeading(-y); contentStream.getOutputStream() .writeFloat(x) .writeSpace() .writeFloat(y) .writeSpace() .writeBytes(TD); return this; }
/** * Changes the value of the <VAR>line dash pattern</VAR>. * <br> * The line dash pattern controls the pattern of dashes and gaps used to stroke paths. * It is specified by an <I>array</I> and a <I>phase</I>. The array specifies the length * of the alternating dashes and gaps. The phase specifies the distance into the dash * pattern to start the dash. * * @param phase the value of the phase * @param unitsOn the number of units that must be 'on' * @param unitsOff the number of units that must be 'off' * @return current canvas. */ public PdfCanvas setLineDash(float unitsOn, float unitsOff, float phase) { currentGs.setDashPattern(getDashPatternArray(new float[]{unitsOn, unitsOff}, phase)); contentStream.getOutputStream().writeByte('[').writeFloat(unitsOn).writeSpace() .writeFloat(unitsOff).writeByte(']').writeSpace() .writeFloat(phase).writeSpace() .writeBytes(d); return this; }
/** * Sets the character spacing parameter. * * @param charSpacing a parameter * @return current canvas. */ public PdfCanvas setCharacterSpacing(float charSpacing) { currentGs.setCharSpacing(charSpacing); contentStream.getOutputStream() .writeFloat(charSpacing).writeSpace() .writeBytes(Tc); return this; }
/** * Sets the word spacing parameter. * * @param wordSpacing a parameter * @return current canvas. */ public PdfCanvas setWordSpacing(float wordSpacing) { currentGs.setWordSpacing(wordSpacing); contentStream.getOutputStream() .writeFloat(wordSpacing).writeSpace() .writeBytes(Tw); return this; }
/** * Sets the horizontal scaling parameter. * * @param scale a parameter. * @return current canvas. */ public PdfCanvas setHorizontalScaling(float scale) { currentGs.setHorizontalScaling(scale); contentStream.getOutputStream() .writeFloat(scale) .writeSpace() .writeBytes(Tz); return this; }
/** * Sets the text rise parameter. * <br> * This allows to write text in subscript or superscript mode. * <br> * * @param textRise a parameter * @return current canvas. */ public PdfCanvas setTextRise(float textRise) { currentGs.setTextRise(textRise); contentStream.getOutputStream() .writeFloat(textRise).writeSpace() .writeBytes(Ts); return this; }
/** * Sets the text leading parameter. * <br> * The leading parameter is measured in text space units. It specifies the vertical distance * between the baselines of adjacent lines of text. *<br> * * @param leading the new leading. * @return current canvas. */ public PdfCanvas setLeading(float leading) { currentGs.setLeading(leading); contentStream.getOutputStream() .writeFloat(leading) .writeSpace() .writeBytes(TL); return this; }
/** * Changes the value of the <VAR>line dash pattern</VAR>. * <br> * The line dash pattern controls the pattern of dashes and gaps used to stroke paths. * It is specified by an <I>array</I> and a <I>phase</I>. The array specifies the length * of the alternating dashes and gaps. The phase specifies the distance into the dash * pattern to start the dash. * * @param phase the value of the phase * @param unitsOn the number of units that must be 'on' (equals the number of units that must be 'off'). * @return current canvas. */ public PdfCanvas setLineDash(float unitsOn, float phase) { currentGs.setDashPattern(getDashPatternArray(new float[]{unitsOn}, phase)); contentStream.getOutputStream().writeByte('[').writeFloat(unitsOn).writeByte(']').writeSpace() .writeFloat(phase).writeSpace() .writeBytes(d); return this; }
/** * Moves to the next line and shows text string, using the given values of the character and word spacing parameters. * * @param wordSpacing a parameter * @param charSpacing a parameter * @param text the text to write * @return current canvas. */ public PdfCanvas newlineShowText(float wordSpacing, float charSpacing, String text) { contentStream.getOutputStream() .writeFloat(wordSpacing) .writeSpace() .writeFloat(charSpacing); showTextInt(text); contentStream.getOutputStream() .writeByte('"') .writeNewLine(); // The " operator sets charSpace and wordSpace into graphics state // (cfr PDF reference v1.6, table 5.6) currentGs.setCharSpacing(charSpacing); currentGs.setWordSpacing(wordSpacing); return this; }
/** * Sets line width. * * @param lineWidth line width. * @return current canvas. */ public PdfCanvas setLineWidth(float lineWidth) { if (currentGs.getLineWidth() == lineWidth) { return this; } currentGs.setLineWidth(lineWidth); contentStream.getOutputStream() .writeFloat(lineWidth).writeSpace() .writeBytes(w); return this; }
/** * Sets the miter limit, a parameter specifying the maximum length a miter join * may extend beyond the join point, relative to the angle of the line segments. * * @param miterLimit * @return current canvas. */ public PdfCanvas setMiterLimit(float miterLimit) { if (currentGs.getMiterLimit() == miterLimit) return this; currentGs.setMiterLimit(miterLimit); contentStream.getOutputStream() .writeFloat(miterLimit).writeSpace() .writeBytes(M); return this; }
/** * Changes the value of the <VAR>line dash pattern</VAR>. * <br> * The line dash pattern controls the pattern of dashes and gaps used to stroke paths. * It is specified by an <I>array</I> and a <I>phase</I>. The array specifies the length * of the alternating dashes and gaps. The phase specifies the distance into the dash * pattern to start the dash. * * @param array length of the alternating dashes and gaps * @param phase the value of the phase * @return current canvas. */ public PdfCanvas setLineDash(float[] array, float phase) { currentGs.setDashPattern(getDashPatternArray(array, phase)); PdfOutputStream out = contentStream.getOutputStream(); out.writeByte('['); for (int iter = 0; iter < array.length; iter++) { out.writeFloat(array[iter]); if (iter < array.length - 1) out.writeSpace(); } out.writeByte(']').writeSpace().writeFloat(phase).writeSpace().writeBytes(d); return this; }
/** * Changes the <VAR>Flatness</VAR>. * <br> * <VAR>Flatness</VAR> sets the maximum permitted distance in device pixels between the * mathematically correct path and an approximation constructed from straight line segments.<BR> * * @param flatnessTolerance a value * @return current canvas. */ public PdfCanvas setFlatnessTolerance(float flatnessTolerance) { if (currentGs.getFlatnessTolerance() == flatnessTolerance) return this; currentGs.setFlatnessTolerance(flatnessTolerance); contentStream.getOutputStream() .writeFloat(flatnessTolerance).writeSpace() .writeBytes(i); return this; }
/** * Changes the value of the <VAR>line dash pattern</VAR>. * <br> * The line dash pattern controls the pattern of dashes and gaps used to stroke paths. * It is specified by an <I>array</I> and a <I>phase</I>. The array specifies the length * of the alternating dashes and gaps. The phase specifies the distance into the dash * pattern to start the dash. * * @param phase the value of the phase * @return current canvas. */ public PdfCanvas setLineDash(float phase) { currentGs.setDashPattern(getDashPatternArray(phase)); contentStream.getOutputStream().writeByte('[').writeByte(']').writeSpace() .writeFloat(phase).writeSpace() .writeBytes(d); return this; }
/** * Sets font and size (PDF Tf operator). * * @param font The font * @param size The font size. * @return The edited canvas. */ public PdfCanvas setFontAndSize(PdfFont font, float size) { currentGs.setFontSize(size); PdfName fontName = resources.addFont(document, font); currentGs.setFont(font); contentStream.getOutputStream() .write(fontName) .writeSpace() .writeFloat(size).writeSpace() .writeBytes(Tf); return this; }
contentStream.getOutputStream().writeBytes(Tj); contentStream.getOutputStream() .writeFloat(getSubrangeWidth(text, sub, i - 1), true) .writeSpace() .writeFloat(0) .writeSpace() .writeBytes(Td); .writeFloat(xPlacement, true) .writeSpace() .writeFloat(yPlacement, true) .writeSpace() .writeBytes(Td); if (!Float.isNaN(xPlacement)) { contentStream.getOutputStream() .writeFloat(-xPlacement, true) .writeSpace() .writeFloat(-yPlacement, true) .writeSpace() .writeBytes(Td); .writeFloat((((glyph.hasPlacement() ? 0 : glyph.getWidth()) + glyph.getXAdvance()) * fontSize + charSpacing + getWordSpacingAddition(glyph)) * scaling, true) .writeSpace() .writeFloat(glyph.getYAdvance() * fontSize, true) .writeSpace() .writeBytes(Td); .writeFloat(getSubrangeWidth(text, sub, glyphLinePart.end - 1), true)
/** * Shows text (operator TJ) * * @param textArray the text array. Each element of array can be a string or a number. * If the element is a string, this operator shows the string. * If it is a number, the operator adjusts the text position by that amount. * The number is expressed in thousandths of a unit of text space. * This amount is subtracted from the current horizontal or vertical coordinate, depending on the writing mode. * @return current canvas. */ public PdfCanvas showText(PdfArray textArray) { if (currentGs.getFont() == null) throw new PdfException(PdfException.FontAndSizeMustBeSetBeforeWritingAnyText, currentGs); contentStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("[")); for (PdfObject obj : textArray) { if (obj.isString()) { StreamUtil.writeEscapedString(contentStream.getOutputStream(), ((PdfString) obj).getValueBytes()); } else if (obj.isNumber()) { contentStream.getOutputStream().writeFloat(((PdfNumber) obj).floatValue()); } } contentStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("]")); contentStream.getOutputStream().writeBytes(TJ); return this; }