Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdfStringObject"/> class.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="encoding">The encoding.</param>
 public PdfStringObject(string value, PdfStringEncoding encoding)
 {
   this.value = value;
   //if ((flags & PdfStringFlags.EncodingMask) == 0)
   //  flags |= PdfStringFlags.PDFDocEncoding;
   this.flags = (PdfStringFlags)encoding;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdfStringObject"/> class.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="encoding">The encoding.</param>
 public PdfStringObject(string value, PdfStringEncoding encoding)
 {
     _value = value;
     //if ((flags & PdfStringFlags.EncodingMask) == 0)
     //  flags |= PdfStringFlags.PDFDocEncoding;
     _flags = (PdfStringFlags)encoding;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Converts a raw string into a raw hexadecimal string literal, possibly encrypted.
        /// </summary>
        public static string ToHexStringLiteral(string text, PdfStringEncoding encoding, PdfStandardSecurityHandler securityHandler)
        {
            if (String.IsNullOrEmpty(text))
            {
                return("<>");
            }

            byte[] bytes;
            switch (encoding)
            {
            case PdfStringEncoding.RawEncoding:
                bytes = RawEncoding.GetBytes(text);
                break;

            case PdfStringEncoding.WinAnsiEncoding:
                bytes = WinAnsiEncoding.GetBytes(text);
                break;

            case PdfStringEncoding.PDFDocEncoding:
                bytes = DocEncoding.GetBytes(text);
                break;

            case PdfStringEncoding.Unicode:
                //bytes = UnicodeEncoding.GetBytes(text);
                bytes = RawUnicodeEncoding.GetBytes(text);
                break;

            default:
                throw new NotImplementedException(encoding.ToString());
            }

            byte[] agTemp = FormatStringLiteral(bytes, encoding == PdfStringEncoding.Unicode, true, true, securityHandler);
            return(RawEncoding.GetString(agTemp, 0, agTemp.Length));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdfString"/> class.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="encoding">The encoding.</param>
        public PdfString(string value, PdfStringEncoding encoding)
        {
            switch (encoding)
            {
            case PdfStringEncoding.RawEncoding:
                CheckRawEncoding(value);
                break;

            case PdfStringEncoding.StandardEncoding:
                break;

            case PdfStringEncoding.PDFDocEncoding:
                break;

            case PdfStringEncoding.WinAnsiEncoding:
                CheckRawEncoding(value);
                break;

            case PdfStringEncoding.MacRomanEncoding:
                break;

            case PdfStringEncoding.Unicode:
                break;

            default:
                throw new ArgumentOutOfRangeException("encoding");
            }
            _value = value;
            //if ((flags & PdfStringFlags.EncodingMask) == 0)
            //  flags |= PdfStringFlags.PDFDocEncoding;
            _flags = (PdfStringFlags)encoding;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdfString"/> class.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="encoding">The encoding.</param>
 public PdfString(string value, PdfStringEncoding encoding)
 {
     this.value = value;
     //if ((flags & PdfStringFlags.EncodingMask) == 0)
     //  flags |= PdfStringFlags.PDFDocEncoding;
     flags = (PdfStringFlags)encoding;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Writes the specified value to the PDF stream.
        /// </summary>
        public void Write(PdfString value)
        {
            WriteSeparator(CharCat.Delimiter);
            PdfStringEncoding encoding = (PdfStringEncoding)(value.Flags & PdfStringFlags.EncodingMask);
            string            pdf      = (value.Flags & PdfStringFlags.HexLiteral) == 0 ?
                                         PdfEncoders.ToStringLiteral(value.Value, encoding, SecurityHandler) :
                                         PdfEncoders.ToHexStringLiteral(value.Value, encoding, SecurityHandler);

            WriteRaw(pdf);
            _lastCat = CharCat.Delimiter;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns the string.
        /// </summary>
        public override string ToString()
        {
#if true
            PdfStringEncoding encoding = (PdfStringEncoding)(_flags & PdfStringFlags.EncodingMask);
            string            pdf      = (_flags & PdfStringFlags.HexLiteral) == 0 ?
                                         PdfEncoders.ToStringLiteral(_value, encoding, null) :
                                         PdfEncoders.ToHexStringLiteral(_value, encoding, null);
            return(pdf);
#else
            return(_value);
#endif
        }
Exemplo n.º 8
0
        /// <summary>
        /// Writes the specified value to the PDF stream.
        /// </summary>
        public void Write(PdfString value)
        {
            WriteSeparator(CharCat.Delimiter);
#if true
            PdfStringEncoding encoding = (PdfStringEncoding)(value.Flags & PdfStringFlags.EncodingMask);
            string            pdf;
            if ((value.Flags & PdfStringFlags.HexLiteral) == 0)
            {
                pdf = PdfEncoders.ToStringLiteral(value.Value, encoding, SecurityHandler);
            }
            else
            {
                pdf = PdfEncoders.ToHexStringLiteral(value.Value, encoding, SecurityHandler);
            }
            WriteRaw(pdf);
#else
            switch (value.Flags & PdfStringFlags.EncodingMask)
            {
            case PdfStringFlags.Undefined:
            case PdfStringFlags.PDFDocEncoding:
                if ((value.Flags & PdfStringFlags.HexLiteral) == 0)
                {
                    WriteRaw(PdfEncoders.DocEncode(value.Value, false));
                }
                else
                {
                    WriteRaw(PdfEncoders.DocEncodeHex(value.Value, false));
                }
                break;

            case PdfStringFlags.WinAnsiEncoding:
                throw new NotImplementedException("Unexpected encoding: WinAnsiEncoding");

            case PdfStringFlags.Unicode:
                if ((value.Flags & PdfStringFlags.HexLiteral) == 0)
                {
                    WriteRaw(PdfEncoders.DocEncode(value.Value, true));
                }
                else
                {
                    WriteRaw(PdfEncoders.DocEncodeHex(value.Value, true));
                }
                break;

            case PdfStringFlags.StandardEncoding:
            case PdfStringFlags.MacRomanEncoding:
            case PdfStringFlags.MacExpertEncoding:
            default:
                throw new NotImplementedException("Unexpected encoding");
            }
#endif
            this.lastCat = CharCat.Delimiter;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Writes the specified value to the PDF stream.
        /// </summary>
        public void Write(PdfString value)
        {
            WriteSeparator(CharCat.Delimiter);
//#if true
            PdfStringEncoding encoding = (PdfStringEncoding)(value.Flags & PdfStringFlags.EncodingMask);
            string            pdf      = (value.Flags & PdfStringFlags.HexLiteral) == 0 ?
                                         PdfEncoders.ToStringLiteral(value.Value, encoding, SecurityHandler) :
                                         PdfEncoders.ToHexStringLiteral(value.Value, encoding, SecurityHandler);

            WriteRaw(pdf);
//#else
//            switch (value.Flags & PdfStringFlags.EncodingMask)
//            {
//                case PdfStringFlags.Undefined:
//                case PdfStringFlags.PDFDocEncoding:
//                    if ((value.Flags & PdfStringFlags.HexLiteral) == 0)
//                        WriteRaw(PdfEncoders.DocEncode(value.Value, false));
//                    else
//                        WriteRaw(PdfEncoders.DocEncodeHex(value.Value, false));
//                    break;

//                case PdfStringFlags.WinAnsiEncoding:
//                    throw new NotImplementedException("Unexpected encoding: WinAnsiEncoding");

//                case PdfStringFlags.Unicode:
//                    if ((value.Flags & PdfStringFlags.HexLiteral) == 0)
//                        WriteRaw(PdfEncoders.DocEncode(value.Value, true));
//                    else
//                        WriteRaw(PdfEncoders.DocEncodeHex(value.Value, true));
//                    break;

//                case PdfStringFlags.StandardEncoding:
//                case PdfStringFlags.MacRomanEncoding:
//                case PdfStringFlags.MacExpertEncoding:
//                default:
//                    throw new NotImplementedException("Unexpected encoding");
//            }
//#endif
            _lastCat = CharCat.Delimiter;
        }
Exemplo n.º 10
0
    /// <summary>
    /// Converts a raw string into a raw hexadecimal string literal, possibly encrypted.
    /// </summary>
    public static string ToHexStringLiteral(string text, PdfStringEncoding encoding, PdfStandardSecurityHandler securityHandler)
    {
      if (text == null || text == "")
        return "<>";

      byte[] bytes;
      switch (encoding)
      {
        case PdfStringEncoding.RawEncoding:
          bytes = PdfEncoders.RawEncoding.GetBytes(text);
          break;

        case PdfStringEncoding.WinAnsiEncoding:
          bytes = PdfEncoders.WinAnsiEncoding.GetBytes(text);
          break;

        case PdfStringEncoding.PDFDocEncoding:
          bytes = PdfEncoders.DocEncoding.GetBytes(text);
          break;

        case PdfStringEncoding.Unicode:
          bytes = PdfEncoders.UnicodeEncoding.GetBytes(text);
          break;

        default:
          throw new NotImplementedException(encoding.ToString());
      }
      return PdfEncoders.RawEncoding.GetString(FormatStringLiteral(bytes, encoding == PdfStringEncoding.Unicode, true,
        true, securityHandler));
    }
Exemplo n.º 11
0
    /// <summary>
    /// Converts a raw string into a raw hexadecimal string literal, possibly encrypted.
    /// </summary>
    public static string ToHexStringLiteral(string text, PdfStringEncoding encoding, PdfStandardSecurityHandler securityHandler)
    {
      if (String.IsNullOrEmpty(text))
        return "<>";

      byte[] bytes;
      switch (encoding)
      {
        case PdfStringEncoding.RawEncoding:
          bytes = RawEncoding.GetBytes(text);
          break;

        case PdfStringEncoding.WinAnsiEncoding:
          bytes = WinAnsiEncoding.GetBytes(text);
          break;

        case PdfStringEncoding.PDFDocEncoding:
          bytes = DocEncoding.GetBytes(text);
          break;

        case PdfStringEncoding.Unicode:
          bytes = UnicodeEncoding.GetBytes(text);
          break;

        default:
          throw new NotImplementedException(encoding.ToString());
      }

      byte[] agTemp = FormatStringLiteral(bytes, encoding == PdfStringEncoding.Unicode, true, true, securityHandler);
      return RawEncoding.GetString(agTemp, 0, agTemp.Length);
    }
Exemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdfString"/> class.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="encoding">The encoding.</param>
        public PdfString(string value, PdfStringEncoding encoding)
        {
            switch (encoding)
            {
                case PdfStringEncoding.RawEncoding:
                    CheckRawEncoding(value);
                    break;

                case PdfStringEncoding.StandardEncoding:
                    break;

                case PdfStringEncoding.PDFDocEncoding:
                    break;

                case PdfStringEncoding.WinAnsiEncoding:
                    CheckRawEncoding(value);
                    break;

                case PdfStringEncoding.MacRomanEncoding:
                    break;

                case PdfStringEncoding.Unicode:
                    break;

                default:
                    throw new ArgumentOutOfRangeException("encoding");
            }
            _value = value;
            //if ((flags & PdfStringFlags.EncodingMask) == 0)
            //  flags |= PdfStringFlags.PDFDocEncoding;
            _flags = (PdfStringFlags)encoding;
        }