Пример #1
0
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        /// <summary>
        /// RtfToXamlLexer
        /// </summary>
        internal RtfToXamlLexer(byte[] rtfBytes)
        {
            _rtfBytes = rtfBytes;

            _currentCodePage = CultureInfo.CurrentCulture.TextInfo.ANSICodePage;
            _currentEncoding = InternalEncoding.GetEncoding(_currentCodePage);
        }
Пример #2
0
        internal static void GetClipboardContentForHtml(StringBuilder content)
        {
            const int bytecountPrefixContext = 135; // Byte count of context before the content in the HTML format
            const int bytecountSuffixContext = 36;  // Byte count of context after the content in the HTML format

            content.Insert(0, "<TABLE>");
            content.Append("</TABLE>");

            // The character set supported by the clipboard is Unicode in its UTF-8 encoding.
            // There are characters in Asian languages which require more than 2 bytes for encoding into UTF-8
            // Marshal.SystemDefaultCharSize is 2 and would not be appropriate in all cases. We have to explicitly calculate the number of bytes.
            byte[] sourceBytes      = Encoding.Unicode.GetBytes(content.ToString());
            byte[] destinationBytes = InternalEncoding.Convert(Encoding.Unicode, Encoding.UTF8, sourceBytes);

            int    bytecountEndOfFragment = bytecountPrefixContext + destinationBytes.Length;
            int    bytecountEndOfHtml     = bytecountEndOfFragment + bytecountSuffixContext;
            string prefix = string.Format(CultureInfo.InvariantCulture, DATAGRIDVIEW_htmlPrefix, bytecountEndOfHtml.ToString("00000000", CultureInfo.InvariantCulture), bytecountEndOfFragment.ToString("00000000", CultureInfo.InvariantCulture)) + DATAGRIDVIEW_htmlStartFragment;

            content.Insert(0, prefix);
            content.Append(DATAGRIDVIEW_htmlEndFragment);
        }