@Override public int hashCode() { String v = getValue(); String e = getEncoding(); int result = v != null ? v.hashCode() : 0; return 31 * result + (e != null ? e.hashCode() : 0); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PdfString that = (PdfString) o; String v1 = getValue(); String v2 = that.getValue(); if (v1 != null && v1.equals(v2)) { String e1 = getEncoding(); String e2 = that.getEncoding(); if ((e1 == null && e2 == null) || (e1 != null && e1.equals(e2))) { return true; } } return false; }
private byte[] convertPdfStringToBytes(PdfString pdfString) { byte[] bytes; String value = pdfString.getValue(); String encoding = pdfString.getEncoding(); if (encoding != null && encoding.equals(PdfEncodings.UNICODE_BIG) && PdfEncodings.isPdfDocEncoding(value)) bytes = PdfEncodings.convertToBytes(value, PdfEncodings.PDF_DOC_ENCODING); else bytes = PdfEncodings.convertToBytes(value, encoding); return bytes; }
/** * Split PDF string into array of single character PDF strings. * * @param string PDF string to be split. * @return split PDF string. */ private PdfString[] splitString(PdfString string) { checkGraphicsState(); PdfFont font = gs.getFont(); if (font instanceof PdfType0Font) { // Number of bytes forming one glyph can be arbitrary from [1; 4] range List<PdfString> strings = new ArrayList<>(); GlyphLine glyphLine = gs.getFont().decodeIntoGlyphLine(string); for (int i = glyphLine.start; i < glyphLine.end; i++) { strings.add(new PdfString(gs.getFont().convertToBytes(glyphLine.get(i)))); } return strings.toArray(new PdfString[strings.size()]); } else { // One byte corresponds to one character PdfString[] strings = new PdfString[string.getValue().length()]; for (int i = 0; i < string.getValue().length(); i++) { strings[i] = new PdfString(string.getValue().substring(i, i + 1), string.getEncoding()); } return strings; } }