internal override void AddChar(String mark, CMapObject code) { try { if (mark.Length == 1) { char[] dest = CreateCharsFromDoubleBytes((byte[])code.GetValue()); byteMappings.Put((int)mark[0], dest); } else { if (mark.Length == 2) { char[] dest = CreateCharsFromDoubleBytes((byte[])code.GetValue()); byteMappings.Put((mark[0] << 8) + mark[1], dest); } else { ILog logger = LogManager.GetLogger(typeof(iText.IO.Font.Cmap.CMapToUnicode)); logger.Warn(iText.IO.LogMessageConstant.TOUNICODE_CMAP_MORE_THAN_2_BYTES_NOT_SUPPORTED); } } } catch (System.IO.IOException) { throw new Exception(); } }
internal override void AddChar(String mark, CMapObject code) { if (code.IsNumber()) { EncodeSequence(DecodeStringToByte(mark), (char)code.GetValue()); } }
internal override void AddChar(String mark, CMapObject code) { if (code.IsNumber()) { byte[] ser = DecodeStringToByte(mark); map.Put((int)code.GetValue(), ser); } }
public static String DecodeCMapObject(CMapObject cMapObject) { if (cMapObject.IsHexString()) { return(PdfEncodings.ConvertToString(((String)cMapObject.GetValue()).GetBytes(), PdfEncodings.UNICODE_BIG_UNMARKED )); } else { return((String)cMapObject.GetValue()); } }
internal override void AddChar(String mark, CMapObject code) { if (code.IsNumber()) { int codePoint; String s = ToUnicodeString(mark, true); if (iText.IO.Util.TextUtil.IsSurrogatePair(s, 0)) { codePoint = iText.IO.Util.TextUtil.ConvertToUtf32(s, 0); } else { codePoint = (int)s[0]; } map.Put(codePoint, (int)code.GetValue()); } }
internal virtual void AddRange(String from, String to, CMapObject code) { byte[] a1 = DecodeStringToByte(from); byte[] a2 = DecodeStringToByte(to); if (a1.Length != a2.Length || a1.Length == 0) { throw new ArgumentException("Invalid map."); } byte[] sout = null; if (code.IsString()) { sout = DecodeStringToByte(code.ToString()); } int start = ByteArrayToInt(a1); int end = ByteArrayToInt(a2); for (int k = start; k <= end; ++k) { IntToByteArray(k, a1); String mark = PdfEncodings.ConvertToString(a1, null); if (code.IsArray()) { IList <CMapObject> codes = (List <CMapObject>)code.GetValue(); AddChar(mark, codes[k - start]); } else { if (code.IsNumber()) { int nn = (int)code.GetValue() + k - start; AddChar(mark, new CMapObject(CMapObject.NUMBER, nn)); } else { if (code.IsString()) { CMapObject s1 = new CMapObject(CMapObject.HEX_STRING, sout); AddChar(mark, s1); System.Diagnostics.Debug.Assert(sout != null); IntToByteArray(ByteArrayToInt(sout) + 1, sout); } } } } }
/// <summary>Reads a dictionary.</summary> /// <remarks> /// Reads a dictionary. The tokeniser must be positioned past the /// <c>"<<"</c> /// token. /// </remarks> /// <returns>the dictionary</returns> /// <exception cref="System.IO.IOException">on error</exception> public virtual CMapObject ReadDictionary() { IDictionary <String, CMapObject> dic = new Dictionary <String, CMapObject>(); while (true) { if (!NextValidToken()) { throw new iText.IO.IOException("Unexpected end of file."); } if (tokeniser.GetTokenType() == PdfTokenizer.TokenType.EndDic) { break; } if (tokeniser.GetTokenType() == PdfTokenizer.TokenType.Other && "def".Equals(tokeniser.GetStringValue())) { continue; } if (tokeniser.GetTokenType() != PdfTokenizer.TokenType.Name) { throw new iText.IO.IOException("Dictionary key {0} is not a name.").SetMessageParams(tokeniser.GetStringValue ()); } String name = tokeniser.GetStringValue(); CMapObject obj = ReadObject(); if (obj.IsToken()) { if (obj.ToString().Equals(">>")) { tokeniser.ThrowError(iText.IO.IOException.UnexpectedGtGt); } if (obj.ToString().Equals("]")) { tokeniser.ThrowError(iText.IO.IOException.UnexpectedCloseBracket); } } dic.Put(name, obj); } return(new CMapObject(CMapObject.DICTIONARY, dic)); }
/// <summary>Reads an array.</summary> /// <remarks>Reads an array. The tokeniser must be positioned past the "[" token.</remarks> /// <returns>an array</returns> /// <exception cref="System.IO.IOException">on error</exception> public virtual CMapObject ReadArray() { IList <CMapObject> array = new List <CMapObject>(); while (true) { CMapObject obj = ReadObject(); if (obj.IsToken()) { if (obj.ToString().Equals("]")) { break; } if (obj.ToString().Equals(">>")) { tokeniser.ThrowError(iText.IO.IOException.UnexpectedGtGt); } } array.Add(obj); } return(new CMapObject(CMapObject.ARRAY, array)); }
internal abstract void AddChar(String mark, CMapObject code);
private static void ParseCid(String cmapName, AbstractCMap cmap, ICMapLocation location, int level) { if (level >= MAX_LEVEL) { return; } PdfTokenizer inp = location.GetLocation(cmapName); try { IList <CMapObject> list = new List <CMapObject>(); CMapContentParser cp = new CMapContentParser(inp); int maxExc = 50; while (true) { try { cp.Parse(list); } catch (Exception) { if (--maxExc < 0) { break; } continue; } if (list.Count == 0) { break; } String last = list[list.Count - 1].ToString(); if (level == 0 && list.Count == 3 && last.Equals(def)) { CMapObject cmapObject = list[0]; if (Registry.Equals(cmapObject.ToString())) { cmap.SetRegistry(list[1].ToString()); } else { if (Ordering.Equals(cmapObject.ToString())) { cmap.SetOrdering(list[1].ToString()); } else { if (CMapName.Equals(cmapObject.ToString())) { cmap.SetName(list[1].ToString()); } else { if (Supplement.Equals(cmapObject.ToString())) { try { cmap.SetSupplement((int)list[1].GetValue()); } catch (Exception) { } } } } } } else { if ((last.Equals(endcidchar) || last.Equals(endbfchar)) && list.Count >= 3) { int lMax = list.Count - 2; for (int k = 0; k < lMax; k += 2) { if (list[k].IsString()) { cmap.AddChar(list[k].ToString(), list[k + 1]); } } } else { if ((last.Equals(endcidrange) || last.Equals(endbfrange)) && list.Count >= 4) { int lMax = list.Count - 3; for (int k = 0; k < lMax; k += 3) { if (list[k].IsString() && list[k + 1].IsString()) { cmap.AddRange(list[k].ToString(), list[k + 1].ToString(), list[k + 2]); } } } else { if (last.Equals(usecmap) && list.Count == 2 && list[0].IsName()) { ParseCid(list[0].ToString(), cmap, location, level + 1); } else { if (last.Equals(endcodespacerange)) { for (int i = 0; i < list.Count + 1; i += 2) { if (list[i].IsHexString() && list[i + 1].IsHexString()) { byte[] low = list[i].ToHexByteArray(); byte[] high = list[i + 1].ToHexByteArray(); cmap.AddCodeSpaceRange(low, high); } } } } } } } } } catch (Exception) { ILog logger = LogManager.GetLogger(typeof(CMapParser)); logger.Error(iText.IO.LogMessageConstant.UNKNOWN_ERROR_WHILE_PROCESSING_CMAP); } finally { inp.Close(); } }
/// <summary>Reads a pdf object.</summary> /// <returns>the pdf object</returns> /// <exception cref="System.IO.IOException">on error</exception> public virtual CMapObject ReadObject() { if (!NextValidToken()) { return(null); } PdfTokenizer.TokenType type = tokeniser.GetTokenType(); switch (type) { case PdfTokenizer.TokenType.StartDic: { return(ReadDictionary()); } case PdfTokenizer.TokenType.StartArray: { return(ReadArray()); } case PdfTokenizer.TokenType.String: { CMapObject obj; if (tokeniser.IsHexString()) { obj = new CMapObject(CMapObject.HEX_STRING, PdfTokenizer.DecodeStringContent(tokeniser.GetByteContent(), true )); } else { obj = new CMapObject(CMapObject.STRING, PdfTokenizer.DecodeStringContent(tokeniser.GetByteContent(), false )); } return(obj); } case PdfTokenizer.TokenType.Name: { return(new CMapObject(CMapObject.NAME, DecodeName(tokeniser.GetByteContent()))); } case PdfTokenizer.TokenType.Number: { CMapObject numObject = new CMapObject(CMapObject.NUMBER, null); try { numObject.SetValue((int)Double.Parse(tokeniser.GetStringValue(), System.Globalization.CultureInfo.InvariantCulture )); } catch (FormatException) { numObject.SetValue(int.MinValue); } return(numObject); } case PdfTokenizer.TokenType.Other: { return(new CMapObject(CMapObject.LITERAL, tokeniser.GetStringValue())); } case PdfTokenizer.TokenType.EndArray: { return(new CMapObject(CMapObject.TOKEN, "]")); } case PdfTokenizer.TokenType.EndDic: { return(new CMapObject(CMapObject.TOKEN, ">>")); } default: { return(new CMapObject(0, "")); } } }