@Override public void writeText(String text, PdfOutputStream stream) { StreamUtil.writeEscapedString(stream, convertToBytes(text)); }
@Override public void writeText(GlyphLine text, int from, int to, PdfOutputStream stream) { byte[] bytes = new byte[to - from + 1]; int ptr = 0; if (fontEncoding.isFontSpecific()) { for (int i = from; i <= to; i++) { bytes[ptr++] = (byte) text.get(i).getCode(); } } else { for (int i = from; i <= to; i++) { if (fontEncoding.canEncode(text.get(i).getUnicode())) { bytes[ptr++] = (byte) fontEncoding.convertToByte(text.get(i).getUnicode()); } } } bytes = ArrayUtil.shortenArray(bytes, ptr); for (byte b : bytes) { shortTag[b & 0xff] = 1; } StreamUtil.writeEscapedString(stream, bytes); }
/** * 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; }